使用 oracle 数据库插入不工作 Node.js
Insert into not working on Node.js with oracle Database
今天我想尝试将数据插入我的 oracle 数据库,但数据无法保存到数据库
这是我的代码
async function db () {
return new Promise( async (resolve, reject) => {
try {
console.log("processing")
connection = await oracle.getConnection(konek);
var result = await connection.execute(`INSERT INTO MS_PERANGKAT (SERIALNUMBER, SSID) VALUES (:1, :2)`, ['12333', 'Rupadana']);
connection = connection.execute("SELECT * FROM ms_perangkat");
resolve(connection)
} catch (err) {
reject(err)
} finally {
if (connection) {
try {
await connection.close();
} catch(err) {
reject(err)
}
}
}
})
}
db().then( async connection => {
console.log(connection)
}).catch(err => {
console.log('Error: ',err)
});
此处输出:
{
metaData: [ { name: 'SERIALNUMBER' }, { name: 'SSID' } ],
rows: [ [ '12333', 'Rupadana' ] ]
}
and here my Oracle Database
发生这种情况是因为尚未提交查询
这里是代码:
var result = await connection.execute(`INSERT INTO MS_PERANGKAT (SERIALNUMBER, SSID) VALUES (:1, :2)`, ['12333', 'Rupadana'],{autoCommit: true});
今天我想尝试将数据插入我的 oracle 数据库,但数据无法保存到数据库 这是我的代码
async function db () {
return new Promise( async (resolve, reject) => {
try {
console.log("processing")
connection = await oracle.getConnection(konek);
var result = await connection.execute(`INSERT INTO MS_PERANGKAT (SERIALNUMBER, SSID) VALUES (:1, :2)`, ['12333', 'Rupadana']);
connection = connection.execute("SELECT * FROM ms_perangkat");
resolve(connection)
} catch (err) {
reject(err)
} finally {
if (connection) {
try {
await connection.close();
} catch(err) {
reject(err)
}
}
}
})
}
db().then( async connection => {
console.log(connection)
}).catch(err => {
console.log('Error: ',err)
});
此处输出:
{
metaData: [ { name: 'SERIALNUMBER' }, { name: 'SSID' } ],
rows: [ [ '12333', 'Rupadana' ] ]
}
and here my Oracle Database
发生这种情况是因为尚未提交查询
这里是代码:
var result = await connection.execute(`INSERT INTO MS_PERANGKAT (SERIALNUMBER, SSID) VALUES (:1, :2)`, ['12333', 'Rupadana'],{autoCommit: true});