【问题标题】:Oracle connectivity with NodeJS and ExpressJSOracle 与 NodeJS 和 ExpressJS 的连接
【发布时间】:2017-05-25 22:26:34
【问题描述】:

我正在尝试将 oracle 与 NodeJS 连接。步骤如下。先决条件除了NodeJS(0.10.25)和npm(1.3.24)外没有安装客户端。

在我的 ExpressJS 项目中:

  • npm install db-oracle
    安装时没有发现错误。

  • 在 app.js 中

    var oracle = require('db-oracle');
    var connString = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxxx)))";
    var connectData = { "tns": connString, "user": "XPPS_OWNER", "password": "Ex3ec" };
    
  • 在我这样编码的端点之一中,

    app.get('/oracleendpoint',function(req,res){
    connectData.connect(function(error) {
      if (error) {
        return console.log("CONNECTION ERROR: " + error);
      }
    
    this.query().select('*').from('Users').execute(function(error, rows) {
        if (error) {
            return console.log('ERROR: ' + error);
        }
        console.log(rows.length + ' ROWS');
       });
    });
    });
    

预期的输出是连接数据库。

仅供参考:数据库实例运行良好。

查询:

  • 数据库名称是什么?
  • 它显示如下所示的错误。造成这种情况的根本原因是什么?

    module.js:340
    throw err;
        ^
    Error: Cannot find module './build/Release/oracle_bindings'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> 
    (C:\xampp\htdocs\mytest\node_modules\db-oracle\db-oracle.js:18:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    

请让我知道任何缺失或需要安装或需要任何节点模块或代码更改。我用谷歌搜索但徒劳无功。没有找到该错误的正确文档。

【问题讨论】:

  • 上述文件夹中是否有文件oracle_bindings?您是否按照包装上的说明进行操作? npmjs.org/package/db-oracle
  • 没有名为 oracle_bindings 的文件,由于我在 windows 系统上工作,我没有按照说明进行操作,我的要求是只需要连接数据库。甚至 oracle 也没有安装在我的本地系统中。它在远程系统中。
  • 很抱歉,但连接到 Oracle 数据库是一项艰巨的任务(这里没有讽刺意味),并且如果您的服务器上至少没有 Oracle 客户端库,则永远不会机器安装。此外,我认为这个库甚至不会在 Windows 系统上编译,也许看看node-oracle

标签: node.js oracle npm


【解决方案1】:

Oracle 自己刚刚发布了适用于 node.js 的 Oracle 驱动程序:https://blogs.oracle.com/opal/entry/introducing_node_oracledb_a_node

看起来很有希望。

【讨论】:

    【解决方案2】:

    在您的示例中,您使用 db-oracle 模块,我建议您改用 node-oracle 模块,因为它更受欢迎/维护得更好。

    要从 Node 连接到 Oracle DB,您必须按照上述页面上的说明进行操作。

    【讨论】:

      猜你喜欢
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 2012-09-09
      • 2021-07-09
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      相关资源
      最近更新 更多