node-oracle的问题
几天把node-oralce模块安装好了,也能够链接数据库但是我有个问题,如果按照以下代码来链接数据库的话,那每一操作都要链接以下数据库,我想能否把链接数据库的操作独立出来?我自己尝试写了下,没搞定,有没有前辈有写好了的借我看看
var oracle = require('oracle');
var connectData = {
hostname: "xxx",
port: 1521,
database: "orcl", // System ID (SID)
user: "xxx",
password: "xxx"
}
oracle.connect(connectData, function(err, connection) {
if (err) { console.log("Error connecting to db:", err); return; }
connection.execute("call procvarchar2outparam(:1,:2)", ["node", new oracle.OutParam(oracle.OCCISTRING, {size: 40})], function(err, results) {
if (err) { console.log("Error executing query:", err); return; }
console.log(results);
connection.close(); // call only when query is finished executing
});
});