简体   繁体   中英

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.

It seems to have installed correctly and I can run require('ibm_db'). Using the sample code provided (nodedb2test.js), no matter what database parameters I use I get the error:

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? It appears below v9.1 drivers are not available.

We can use ibm_db without installing IBM Data Server Driver Package too. ibm_db internally uses DB2 V10.5FP5 ODBC/CLI driver to talk to DB2 server. Please share the platform info and OS version where you have installed ibm_db. In june'14, ibm_db was supported on Linuxppc, AIX and zLinux platforms, but latest release is supporting. If latest driver is not working for you, please open an issue on 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.platform" win32

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

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');
    });

  });

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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