• JS连接数据库“实例”


    示例1:(必须建立ODBC数据源)

    <HTML>

    <script language=javascript>

    function connectDb()

    {

    var ConnDB = new ActiveXObject("ADODB.Connection");

        ConnDB.ConnectionString="dsn=test3d;uid=;pwd=;";

        ConnDB.Open();

    var    Rs = new ActiveXObject("ADODB.Recordset");

    var tempstr="";

    Rs.Open("select   result   from   Issue_3D where result='071'",ConnDB,1,3);

    while(!Rs.EOF)

    {

        tempstr = tempstr + Rs("result") + "<br/>";

        Rs.MoveNext;

    }

        test.innerHTML=tempstr;

    }

    </script>

    <BODY onbeforeunload="return 'ok?'">

    <P><div id=test>&nbsp;</div>

    <P><INPUT id=button1 type=button value=显示 name=button1 onclick="connectDb()"></P>

    </BODY>

    </HTML>

    示例2:(直接连接,不用建立数据源,就是OLEDB模式)

    <script language=javascript>

    var db="C:\\Documents and Settings\\Administrator\\桌面\\test3d.mdb";

    function connectDb()

    {

    var rs=new ActiveXObject("ADODB.Recordset");

    rs.open("select   result   from   Issue_3D where result='071'","provider=microsoft.jet.oledb.4.0;data source=z:\\test_3D.mdb;User ID=;Password=",1,3);

    document.all.test.innerHTML=rs("result").value;

    rs.close();

    }

    </script>

    <HTML>

    <BODY onbeforeunload="return 'ok?'">

    <P><div id=test>&nbsp;</div>

    <P><INPUT id=button1 type=button value=显示 name=button1 onclick="connectDb()"></P>

    </BODY>

    </HTML>

    CSDN.NET参考资料:

    1.

    set dbconnection=Server.CREATEOBJECT("ADODB.CONNECTION")

    DBPath = Server.MapPath("customer.mdb")

    dbconnection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath

    SQL="select * from auth where id='" & user_id &"'"

    SET uplist=dbconnection.EXECUTE(SQL)

    2.

    set dbconnection=Server.CreateObject("ADODB.Connection")

    DBPath = Server.MapPath("customer.mdb")

    dbconnection.Open "provider=microsoft.jet.oledb.4.0;data source="&dbpath

    SQL="select * from auth where id='" & user_id &"'"

    SET uplist=dbconnection.EXECUTE(SQL)

    3.

    DBPath = Server.MapPath("customer.mdb")

    set session("rs")=Server.CreateObject("ADODB.Recordset")

    ' rs=Server.CreateObject("ADODB.Recordset")

    connstr="provider=microsoft.jet.oledb.4.0;data source="&dbpath

    SQL="select * from auth where id='" & user_id &"'"

    session("rs").Open sql,connstr,1,3

    4.

    建odbc源xxx

    set conn=server.createobject("Adodb.connection")

    conn.open "DSN=xxx;UID=;PWD=;Database=customer

  • 相关阅读:
    (译)linux系统关于命令echo的15个例子
    linux之grep实例讲解
    linux grep练习
    (译)"usermod"命令使用完全指导---15个练习例程截图
    linux分区,文件系统,目录结构概述
    Linux 配置YUM
    Linux 强制安装rpm 包
    $LANG、$NLS_LANG 记录一下
    Oracle性能诊断艺术-相关脚本说明
    datafile相关(add、rename、drop)
  • 原文地址:https://www.cnblogs.com/xred/p/2604616.html
Copyright © 2020-2023  润新知