IBM Cloud

IBM Cloud functions(node.js) 中 和DB2的连接方法

可以在IBM Cloud Function中用下面的方法连接Cloud DB2

var ibmdb = require('ibm_db');
function main(params) {

var ssldsn = 'DATABASE=xxxxx;HOSTNAME=dashdb-txn-flex-yp-xxxxx.xxxxxx.xxxxx.bluemix.net;PORT=xxxxx;PROTOCOL=TCPIP;UID=xxxxx;PWD=xxxxx;Security=SSL;';
var sql = 'select * from SYSIBMADM.SNAPDBM';

ibmdb.open(ssldsn, function (err,conn) {
  if (err) return console.log(err);

  conn.query(sql, function (err, data) {
    if (err) console.log(err);
    else console.log(data);

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


};

Mysql的例子:https://medium.com/@taiponrock/ibm-cloud-functions%E3%81%AE%E5%AE%9F%E8%A3%85%E3%82%92%E5%AD%A6%E3%81%B6-8b2b9b618e16