我想使用以下代码中引用的insertIntoTable将数据插入Oracle数据库表;该功能无法正常工作,但是如果没有它,查询将按预期工作。

let connection;
var oracledb = require('oracledb');

(async function() {
try{

    connection = await oracledb.getConnection({
    user : 'demo7',
    password : 'dbpass',
    connectString : 'localhost/induspdb'
    });
    console.log("Successfully connected to Oracle!");

  //function which insert result into table
    async function insertIntoTable(dateToday, fileFound, fileNotFound )
    {
    const query='insert into backupinfo (infdate,found,notfound) values (:1,:2,:3)';
    var binds=[dateToday,fileFound,fileNotFound];
    await connection.execute(query , binds, {autoCommit:true});
    }

  // module.exports.insertIntoTable=insertIntoTable;
  insertIntoTable('2019-09-06','rtx','agh');

} catch(err) {
    console.log("Error: ", err);
  } finally {
    if (connection) {
      try {
        await connection.close();
      } catch(err) {
        console.log("Error when closing the database connection: ", err);
      }
    }
  }

})()


每当我调用此函数并传递给定参数时,此函数应将值插入表中,这是错误输出:

Successfully connected to Oracle!

    (node:10088) UnhandledPromiseRejectionWarning: Error: DPI-1010: not connected
    (node:10088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an as
    ync function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:10088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are n
    ot handled will terminate the Node.js process with a non-zero exit code.

最佳答案

根据数据库中的表类型检查绑定的所有参数是否有效。
另外,在insertIntoTable“ await”之前添加,这样该错误将不会被UnhandledPromiseRejection清除,并且将更加清晰。

09-25 18:50
查看更多