0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Node.js: OracleDB のデータを更新 (Update)

0
Posted at

プログラム

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?