To connect to Db2 with node-ibm_db, you will need to set a connection string, which will include information for connection such as your database name (Datasource name or DSN) and authentication credentials. An example connection string would look like this: const connStr = ‘DSN=[YOUR_DATASOURCE_NAME];UID=[YOUR_UID];PWD=xxxxxxx’ Or an alternate way would be setting the environment variable: export IBM_DB_DBNAME=[YOUR_DATASOURCE_NAME] export IBM_DB_UID=[YOUR_UID] export IBM_DB_PWD=”xxxxxxx” You can open the connection with the connection string: ibmdb.open(connStr, function (err, conn) { //… }); Or you can open the connection synchronously: const conn = ibmdb.openSync(connStr); Querying You can query Db2 by calling the query method on the Database object, which is returned after successfully opened a connection: ibmdb.open(connStr, function (err, conn) { conn.query(‘create table mytab1 (c1 int, c2 varchar(10));’, function (err, data) { ...
Comments
Post a Comment