<script language= "JavaScript" >//Create database object var objdbconn = new ActiveXObject ("ADODB. Connection ");//DSN string var strdsn =" Driver={sql Server}; server=127.0.0.1; Uid=sa; Pwd=sa;database=coa ";//Open Data source Objdbconn.open (STRDSN);//database query to execute SQL var objRS = objdbconn.execute (" Select Menu_name From Basic_mainmenu ");//Gets the number of fields var Fdcount = objRS. fields.count-1;//Check if there is a record if (!objrs. EOF) {document.write ("<table border=1><tr>");//Display the field name of the database for (var i=0; I <= fdcount; i++) document.write ("<td><b>" + objRS. Fields (i). Name + "</b></td>");d ocument.write ("</tr>");//Display database contents while (!objrs. EOF) {document.write ("<tr>");//show fields for each record for (i=0; I <= fdcount; i++) document.write ("<td valign= ' top ' >" + objRS. Fields (i). Value + "</td>");d ocument.write ("</tr>"); Objrs.movenext (); Move to the next record}document.write ("</table>");} Elsedocument.write ("No record!<br> in database"); objRS. Close (); Close record set Objdbconn.close (); Close database links </script>
http://javamao.iteye.com/blog/625404
JS connects SQL Server for querying