JavaScript用什么开发工具
JavaScript怎么连接oracle谢谢回答

解决方案 »

  1.   

    用javascript直接连接数据库????
    太高深了,没玩过.....
      

  2.   

    JS一般用于网页中,不能连接数据库
    如果是在本地,比如把后缀改成hta这样,倒是可以连接,不过我只连接过access,oracle没试过
    把下面的代码写到一个文本里面,然后另存为test.hta就可以用了<html>
    <title>HTA数据库连接程序</title>
    <HTA:Application 
       border="thin"
       caption="yes"
       maximizebutton="no"
       minimizebutton="yes"
       sysmenu="yes"
       windowstate="normal"
       icon="F:\My Document\My Pictures\图标\ICO\常用工具图标\无标题 (42).ico"
    >
    <style>
    body{
    margin:10px;
    overflow-y:hidden;
    overflow-x:hidden
    }
    body{
    FONT-FAMILY:Tahoma,"宋体";
    font-size:12px;
    background-color:#D4D0C8;
    }
    </style>
    <script>
    function JSDB()
    {
      this.connection = null;
      this.rs = null;
    }//初始化连接
    //db_file 数据库文件名
    JSDB.prototype.init = function(db_file)
    {
      try{ 
        this.connection=new ActiveXObject("ADODB.Connection"); 
        this.rs=new ActiveXObject("ADODB.Recordset"); 
        var connectString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db_file;    
        this.connection.open(connectString);     
        return true;
      } 
      catch(e) 
      { 
        alert("连接数据库时发生异常:\r\n"+e.name+" : "+e.message);
        return false;
      } 
    }//查询数据库
    //query 查询语句
    //queryFunc 对查询结果进行操作的函数,可以没有
    JSDB.prototype.query = function(queryString,queryFunc)
    {
      try{
        this.rs=this.connection.execute(queryString); 
        if(queryFunc)
        {
          queryFunc(this.rs);
        }
      }
      catch(e)
      {
        alert("查询时发生异常:\r\n"+e.name+" : "+e.message);
      }
    }//关闭数据库连接
    JSDB.prototype.close = function()
    {
      try{
        this.rs.close();
        this.connection.close();
        return true;
      }
      catch(e)
      {
        return true;
      }
    }
    /********************************************************************/
    var db = new JSDB();
    function connectDB()
    {
      if(db.init("test.mdb"))
        alert("连接成功");
      else
        alert("连接失败");
    }function queryDB()
    {
      db.query("select * from man",function(rs){
        while(!rs.EOF)
        {
          alert(rs(0).value);
          rs.moveNext();
        }
      });
    }function closeDB()
    {
      if(db.close())
        alert("成功关闭");
      else
        alert("关闭失败");
    }
    </script>
    <body onload="window.resizeTo(200, 150)">
    <button onclick="connectDB()">连接数据库</button><br>
    <button onclick="queryDB()">遍历数据</button><br>
    <button onclick="closeDB()">关闭连接</button>
    </body>
    </html>
      

  3.   

    用ODBC当然啥都能连接。不过,很少有人这么干。这个贴子对你的程序员生涯具有纪念意义。
      

  4.   

    js不能链接oracle 用别的吧 .net jsp等