我正在使用oracledb cen node.js模块,并且在进行数据库连接进行选择时,它返回数据,但是还会出现此错误:
(node:1) UnhandledPromiseRejectionWarning: ReferenceError: connection is not defined
at Object.getTest (/home/src/storage/oracleDb.js:29:9)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch().
(rejection id: 1)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我这样查询:
try {
await oracledb.getconnection(config.db)
.then(function (conn) {
return conn.execute(querys.queryTest());
},function(err) {
console.log(err);
})
.then(function (result) {
console.log('Query executed');
console.log(result.rows[0]);
},function(err) {
console.log(err);
})
.catch(function(err) {
console.log(err);
});
} catch (error) {
console.log(error);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}