You can test the node-ibm_db driver
with a sample Node.js application.
Procedure
To verify the node-ibm_db driver installation:
- Create a sample Node.js application to test the connection
to the sample database.
Copy the following sample code
into a file and save the file as
test1.js.
//test1.js
var ibmdb = require('ibm_db');
ibmdb.open("DRIVER={DB2};DATABASE=sample;HOSTNAME=<hostname>;
UID=<user_id>;PWD=<password>;PORT=<port>;
PROTOCOL=TCPIP", function (err,conn) {
if (err) return console.log(err);
conn.query('select * from staff where id = ?', [10], function (err, data) {
if (err) console.log(err);
console.log(data);
conn.close(function () {
console.log('done');
});
});
});
where:
- <hostname> is the fully qualified host name
of your IBM® database server.
- <user_id> and <password> are
a valid user ID and password for connecting to the sample database.
- <port> is the listener port of the IBM database server.
- Run the test1.js application by issuing
the node test1.js command:
C:\Users\IBM_ADMIN>node test1.js
The
node test1.js command results in
the following output.
[ { ID: 10,
NAME: 'Sanders',
DEPT: 20,
JOB: 'Mgr ',
YEARS: 7,
SALARY: 98357.5,
COMM: 1.5537297e-317 } ]
done