You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
904 B
JavaScript

const oracledb = require('oracledb');
// 设置数据库连接参数
const config = {
user: 'system',
password: '452131wW',
connectString : "192.168.3.29:1521/orcl" // 或者直接使用 'hostname:port/sid'
};
async function run() {
let connection;
try {
// 获取数据库连接
connection = await oracledb.getConnection(config);
console.log('Connection established.');
// 执行查询
const result = await connection.execute('SELECT * FROM TYPE');
console.log(result.rows); // 输出查询结果
} catch (err) {
console.error(err);
} finally {
if (connection) {
// 关闭数据库连接
try {
await connection.close();
console.log('Connection closed.');
} catch (err) {
console.error(err);
}
}
}
}