Installing the Db2 for i drivers (ODBC and idb-connector)

Section 3: Installing Node.js on IBM i

Node.js on its own doesn't know a Db2 table from a data area. We need a driver. This is where ODBC steps in.

Install the ODBC pieces with yum

yum install unixODBC unixODBC-devel ibm-iaccess
  • unixODBC is the ODBC driver manager.
  • ibm-iaccess is the IBM i Access ODBC Driver for PASE.

Check the driver is registered:

odbcinst -q -d

You should see [IBM i Access ODBC Driver]. On IBM i there's also a predefined DSN called *LOCAL that connects to the local database.

Test the connection with isql

isql -v '*LOCAL' NICK MYPASSWORD

At the SQL> prompt try:

SELECT CURRENT_SERVER, CURRENT_USER FROM SYSIBM.SYSDUMMY1

Type quit to leave.

Install the npm package

Inside your project directory (we'll create the real one in Section 5):

mkdir -p ~/odbctest && cd ~/odbctest
npm init -y
npm install odbc

Build tools: odbc is a native addon. If npm tries to compile it and fails, install the build chain: yum install gcc10 gcc10-cplusplus make-gnu python39 and try again.

Quick test - odbc

Inside your project directory (we'll create the real one in Section 5):

// test-odbc.js
const odbc = require('odbc');

async function main() {
const conn = await odbc.connect(
`DSN=*LOCAL;UID=${process.env.DB_USER};PWD=${process.env.DB_PASS};NAM=1`
);
const rows = await conn.query(
'SELECT CURRENT_SERVER AS SERVER, CURRENT_USER AS USR FROM SYSIBM.SYSDUMMY1'
);
console.log(rows[0]);
await conn.close();
}

main().catch(err => { console.error(err); process.exit(1); });
DB_USER=NICK DB_PASS='secret' node test-odbc.js

NAM=1 sets system naming (LIBRARY/TABLE and your library list), which feels like home. Leave it off for SQL naming (SCHEMA.TABLE).

Alternative - idb-pconnector (on-box only)

IBM's native connector uses the job's own authority, so no user/password is needed when running on the IBM i:

npm install idb-pconnector
// test-idb.js
const { Connection, Statement } = require('idb-pconnector');

async function main() {
const conn = new Connection({ url: '*LOCAL' });
const stmt = new Statement(conn);
const rows = await stmt.exec(
'SELECT CURRENT_SERVER AS SERVER FROM SYSIBM.SYSDUMMY1'
);
console.log(rows);
await stmt.close();
conn.disconn();
conn.close();
}

main().catch(console.error);

From here on, the course uses odbc. You've now got Node.js, npm and a working database connection. High five!

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>