复制代码 代码如下: <br> //用 JavaScript 写服务器端连接数据库的代码示例 <br> var conn = new ActiveXObject("ADODB.Connection"); <br> conn.Open("DBQ=c:\a.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"); <br> var rs = new ActiveXObject("ADODB.Recordset"); <br> var sql="select * from friends_infor"; <br> rs.open(sql, conn); <br> shtml = "<table width='100%' border=1>"; <br> shtml +="<tr bgcolor='#f4f4f4'><td>au_id</td><td>au_lname</td><td>au_fname</td></tr>"; <br> while(!rs.EOF) <br> { <br> shtml += "<tr><td>" + rs("friend_id") + "</td><td>" + rs("friend_name") + "</td><td>" + rs("friend_nickname") + "</td></tr>"; <br> rs.moveNext; <br> } <br> shtml += "</table>"; <br> document.write(shtml); <br> rs.close(); <br> rs = null; <br> conn.close(); <br> conn = null; <br>