本文目录一览:
- 1、js能不能数据库连接
- 2、求教一段sj连接网页的代码!!
- 3、nodejs使用mongoose怎么连接远程mongo,求示例代码
- 4、javascript怎么与数据库连接
- 5、怎么用javascript连接webservice
- 6、javascript怎么链接access数据库
js能不能数据库连接
楼主是要这个吗?
script language="javascript"
//用 javascript 写服务器端连接数据库的代码示例
function conn(){
var db_bbs
db_bbs="dd.mdb"//定义数据库
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db_bbs+"");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select name from authors"; //数据库中有authors表,name字段
rs.open(sql,conn);
alert(rs(0))//取出第一个来
conn.close();
conn = null;
}
/script
以下的是sql连接
script language="javascript"
//用 javascript 写服务器端连接数据库的代码示例
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; "
+"Password=; Initial Catalog=pubs");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select * from authors";
rs.open(sql, conn);
rs.close();
rs = null;
conn.close();
conn = null;
/script
感觉JS连数据库怪怪的,还是分层吧,毕竟数据库连接这样的东西放表现上不太安全。
求教一段sj连接网页的代码!!
代码示例:
INPUT TYPE="button" onclick="aa(this.value)" VALUE=""BR
INPUT TYPE="button" onclick="aa(this.value)" VALUE=""
SCRIPT LANGUAGE="JavaScript"
function aa(s)
{
a=new ActiveXObject("Microsoft.XMLHTTP")
a.open("GET",s,false);
try{a.send();}catch(e){};
if(a.status==200){
alert("有效连接!");
self.location=s;
}
else
{
alert("连接超时!");
self.location='';
}
}
/SCRIPT
nodejs使用mongoose怎么连接远程mongo,求示例代码
方法如下:
1、按WIN+Q组合键打开搜索框,输入"远程桌面连接",点击下方提示的远程桌面连接
2、在打开的连接窗口,输入远程机器的计算机名或IP地址,和端口
3、系统可能会有一些提示,点击确认。
4、登入远程主机后,输入远程主机的用户名和密码即可
javascript怎么与数据库连接
第一步定义连接字符串
var MM_conn_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\cs\\benlen\\gbmdb.mdb;Persist Security Info=False"
第二步创建adodb对象
var con = Server.CreateObject("ADODB.Connection");con.ActiveConnection = MM_conn_STRING;con.Open();
这下 就连接好了数据库。
第三步创建记录集
var rs = Server.CreateObject("ADODB.Recordset");rs.ActiveConnection = MM_conn_STRING;rs.Source = "SELECT * FROM admin";rs.CursorType = 0;rs.CursorLocation = 2;rs.LockType = 1;rs.Open();var rs_numRows = 0;
这样我们数据库连接就完成了
以下是示例代码:
script type="text/javascript" language="javascript" charset="gb2312"
!--
function getCountFromDB() {
//以当前页面文件为基础,找到文件所在的绝对路径。
var filePath = location.href.substring(0, location.href.indexOf("index.html"));
var path = filePath + "MyData.mdb";
//去掉字符串中最前面的"files://"这8个字符。
path = path.substring(8);
var updateCnt = 0;
//生成查询和更新用的sql语句。
var sqlSelCnt = "SELECT * FROM [user]";
//建立连接,并生成相关字符串。
var con = new ActiveXObject("ADODB.Connection");
con.Provider = "Microsoft.Jet.OLEDB.4.0";
con.ConnectionString = "Data Source=" + path;
con.open;
var rs = new ActiveXObject("ADODB.Recordset");
rs.open (sqlSelCnt,con);
while (!rs.eof) {
var cnt = rs.Fields("content");
document.write (cnt);
rs.moveNext;
}
rs.close();
rs = null;
}
怎么用javascript连接webservice
直接上示例代码 :
MyService.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
/// summary
///MyService 的摘要说明
/// /summary
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService {
public MyService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public XmlNode xml() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("hiHello World/hi");
return doc.FirstChild;
}
[WebMethod]
public string add(int a, int b)
{
return (a + b)+"";
}
}
aspx页面
html xmlns=""
head runat="server"
title/title
script language="javascript" type="text/javascript"
// !CDATA[
function Button1_onclick() {
var data;
data = "?xml version=\"1.0\" encoding=\"utf-8\"?"
+"soap12:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap12=\"\""
+ "soap12:Body"
+ "HelloWorldResponse xmlns=\"\""
+ "HelloWorldResultstring/HelloWorldResult"
+ "/HelloWorldResponse"
+ "/soap12:Body"
+"/soap12:Envelope";
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var URL = "MyService.asmx";
xmlhttp.Open("POST", URL, false);
xmlhttp.SetRequestHeader("Content-Type", "text/xml; charset=gb2312");
xmlhttp.SetRequestHeader("SOAPAction", "");
xmlhttp.setRequestHeader("Content-Length", data.length);
xmlhttp.Send(data);
var xml = xmlhttp.responseText;
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.loadXML(xml);
//alert(doc.selectSingleNode("//HelloWorldResult").text);
//alert(doc.xml);
alert(doc.selectSingleNode("//HelloWorldResponse").childNodes[0].nodeName);
}
function add() {
var a = 10;
var b = 15;
var data;
data = "?xml version=\"1.0\" encoding=\"utf-8\"?"
+ "soap12:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap12=\"\""
+ "soap12:Body"
+ "add xmlns=\"\""
+ "a"+a+"/a"
+ "b"+b+"/b"
+ "/add"
+ "/soap12:Body"
+ "/soap12:Envelope";
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var URL = "MyService.asmx";
xmlhttp.Open("POST", URL, false);
xmlhttp.SetRequestHeader("Content-Type", "text/xml; charset=gb2312");
xmlhttp.SetRequestHeader("SOAPAction", "");
xmlhttp.setRequestHeader("Content-Length", data.length);
xmlhttp.Send(data);
var xml = xmlhttp.responseText;alert(xml);
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.loadXML(xml);
}
function getxml() {
var a = 10;
var b = 15;
var data;
data = "?xml version=\"1.0\" encoding=\"utf-8\"?"
+ "soap12:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap12=\"\""
+ "soap12:Body"
+ "add xmlns=\"\""
+ "/soap12:Body"
+ "/soap12:Envelope";
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var URL = "MyService.asmx";
xmlhttp.Open("POST", URL, false);
xmlhttp.SetRequestHeader("Content-Type", "text/xml; charset=gb2312");
xmlhttp.SetRequestHeader("SOAPAction", "");
xmlhttp.setRequestHeader("Content-Length", data.length);
xmlhttp.Send(data);
var xml = xmlhttp.responseText; alert(xml);
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.loadXML(xml);
}
// ]]
/script
/head
body
form id="form1" runat="server"
div
input id="Button1" type="button" value="button" onclick="getxml()" /
/div
/form
/body
/html
javascript怎么链接access数据库
javascript是可以连接本地数据库的,以下是示例代码:
script type="text/javascript" language="javascript" charset="gb2312"
!--
function getCountFromDB() {
//以当前页面文件为基础,找到文件所在的绝对路径。
var filePath = location.href.substring(0, location.href.indexOf("index.html"));
var path = filePath + "MyData.mdb";
//去掉字符串中最前面的"files://"这8个字符。
path = path.substring(8);
var updateCnt = 0;
//生成查询和更新用的sql语句。
var sqlSelCnt = "SELECT * FROM [user]";
//建立连接,并生成相关字符串。
var con = new ActiveXObject("ADODB.Connection");
con.Provider = "Microsoft.Jet.OLEDB.4.0";
con.ConnectionString = "Data Source=" + path;
con.open;
var rs = new ActiveXObject("ADODB.Recordset");
rs.open (sqlSelCnt,con);
while (!rs.eof) {
var cnt = rs.Fields("content");
document.write (cnt);
rs.moveNext;
}
rs.close();
rs = null;
}