发布网友 发布时间:2022-04-23 05:11
共1个回答
热心网友 时间:2022-04-23 06:41
可以,但是不安全,所以没有实际工程用JS去操作数据库。------------------- //用 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); shtml = ""; shtml +="au_idau_lnameau_fnamephoneaddress citystatezip"; while(!rs.EOF) { shtml += "" + rs("au_id") + "" + rs("au_lname") + "" + rs("au_fname") + "" + rs("phone") + "" + rs("address") + "" + rs("city") + "" + rs("state") + "" + rs("zip") + ""; rs.moveNext; } shtml += ""; document.write(shtml); rs.close(); rs = null; conn.close(); conn = null;