无法将express.js与oracledb连接

时间:2019-07-16 12:15:21

标签: javascript node.js oracle express node-modules

我正在使用express.js连接oracle数据库。问题是当我运行API时,在cmd中出现以下错误

oracledb.getConnection(config, function (err, connection) {
                if (err) console.log(err);

                connection.execute("SELECT * FROM database", function (error, results, fields) {
                    if (error) {
                        console.log(error);
                        res.json({
                            status: false,
                            message: "there are some error with query"
                        })
                    } else {
                        if(results !="" && results!= null && results!= undefined){
                            res.json({
                                data: results,
                                status: true,
                                message: "Data get from db"
                            })
                        }

                    }
                })

            })

TypeError:无法读取未定义的属性“ execute”

因此,在收到此错误后,我在各个站点上进行了搜索,并找到了解决方案,因此我可以通过以下方式更改代码。

(async function () {
        try {
            connection = await oracledb.getConnection({
                user: 'xyz',
                password: 'xyz',
                connectString: 'xyz'
            });

            result = await connection.execute("SELECT * FROM database");
            res.json({
                data: result,
                status: true,
                message: "Data get from db",
                length: results.length
            })
        } catch (err) {
            console.error(err.message);
        } finally {
            if (connection) {
                try {
                    await connection.close(); // Always close connections
                } catch (err) {
                    console.error(err.message);
                }
            }
        }
    })();

但是在实现异步方式之后,我又遇到了另一个错误

can not locate oracle 64bit client library: "some path.../oci.dll is not the correct architecture"...
UnhandledPromisePejectionWarning: connection is not defined....
UnhandledPromisePejectionWarning: this error is originated either by throwing inside of an async function without a catch, block or by rejecting a promise which was not handled with .catch()

我做错了什么吗?

请帮助我。非常感谢

0 个答案:

没有答案