简体   繁体   English

Node.js 到 DB2(使用 ibm_db)

[英]Node.js to DB2 (using ibm_db)

I've followed the instructions: https://www.ibm.com/developerworks/community/blogs/pd/entry/using_ibm_db2_from_node_js4?maxresults=15&page=0&lang=en for a 32-bit install of Ubuntu.我已按照说明操作: https : //www.ibm.com/developerworks/community/blogs/pd/entry/using_ibm_db2_from_node_js4?maxresults=15&page=0&lang=en用于 32 位 Ubuntu 安装。

It seems to have installed correctly and I can run require('ibm_db').它似乎已正确安装,我可以运行 require('ibm_db')。 Using the sample code provided (nodedb2test.js), no matter what database parameters I use I get the error:使用提供的示例代码(nodedb2test.js),无论我使用什么数据库参数,都会出现错误:

node nodedb2test.js
Test program to access DB2 sample database
*** stack smashing detected ***: node terminated
Aborted (core dumped)

Heres the sample code:下面是示例代码:

/*require the ibm_db module*/

var ibmdb = require('ibm_db');
console.log("Test program to access DB2 sample database");

ibmdb.open("DRIVER={DB2};DATABASE=testdb;UID=username;PWD=password;HOSTNAME=localhost;port=3000", function(err, conn)

{
        if(err) {
            console.error("error: ", err.message);
           }

});

Also I looks the version of DB2 I need to connect to is version 6. I have installed BM Data Server Driver version 10.5, does this correspond to the version of DB2?另外我看我需要连接的DB2版本是6版本。我已经安装了BM Data Server Driver 10.5版本,这是否与DB2版本相对应? It appears below v9.1 drivers are not available.看来v9.1以下的驱动程序不可用。

We can use ibm_db without installing IBM Data Server Driver Package too. 我们也可以使用ibm_db而不安装IBM数据服务器驱动程序包。 ibm_db internally uses DB2 V10.5FP5 ODBC/CLI driver to talk to DB2 server. ibm_db在内部使用DB2 V10.5FP5 ODBC / CLI驱动程序与DB2服务器通信。 Please share the platform info and OS version where you have installed ibm_db. 请共享已安装ibm_db的平台信息和操作系统版本。 In june'14, ibm_db was supported on Linuxppc, AIX and zLinux platforms, but latest release is supporting. 14年6月,Linuxppc,AIX和zLinux平台支持ibm_db,但支持最新版本。 If latest driver is not working for you, please open an issue on github.com/ibmdb/node-ibm_db/issues/new . 如果最新的驱动程序不适合您,请在github.com/ibmdb/node-ibm_db/issues/new上打开一个问题。 Thanks. 谢谢。

At time of writing this works for me.在撰写本文时,这对我有用。

C:\\Development\\Javascript>node -p "process.arch" x64 C:\\Development\\Javascript>node -p "process.arch" x64

C:\\Development\\Javascript>node -p "process.platform" win32 C:\\Development\\Javascript>node -p "process.platform" win32

C:\\Development\\Javascript>node -p "process.version" v14.17.5 C:\\Development\\Javascript>node -p "process.version" v14.17.5

C:\\Development\\Javascript>npm install ibm_db C:\\Development\\Javascript>npm install ibm_db

var ibmdb = require("ibm_db");

const config = require("config");
const hostname = config.get("db2.hostname");
const username = config.get("db2.username");
const password = config.get("db2.password");

ibmdb.open("DRIVER={DB2};DATABASE=bludb;HOSTNAME=" + hostname + ";UID=" + username + ";PWD=" + password + ";PORT=31198;PROTOCOL=TCPIP;SECURITY=SSL", function (err, conn){

  if (err) return console.log(err);

  conn.query("SELECT * FROM orders", function (err, data) {

    if (err) console.log(err);

    console.log(data);

    conn.close(function () {
      console.log('done');
    });

  });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM