プログラム
oracle_update.js
#! /usr/bin/node
//
// oracle_update.js
// May/10/2023
//
// ---------------------------------------------------------------
'use strict'
const oracledb = require('oracledb')
// ---------------------------------------------------------------
async function run() {
console.error("*** 開始 ***")
const id_in = process.argv[2]
const population_in = process.argv[3]
console.log(id_in + "\t" + population_in)
let connection
try {
connection = await oracledb.getConnection( {
user: "scott",
password: "tiger123",
connectString: "172.17.0.2:1521/XEPDB1"
})
const sql = `UPDATE cities SET population = :1, date_mod = :2 where id = '` + id_in + `'`
const row = [population_in, new Date()]
const result = await connection.execute( sql,row)
console.log(result)
await connection.commit()
console.error("*** 終了 ***")
} catch (err) {
console.error(err)
} finally {
if (connection) {
try {
await connection.close()
} catch (err) {
console.error(err)
}
}
}
}
// ---------------------------------------------------------------
run()
// ---------------------------------------------------------------
実行コマンド
./oracle_update.js t0135 8952300
確認したバージョン
$ node --version
v19.9.0