To insert multiple rows in a single execution, pass an array of parameter arrays to a prepared statement's exec method.
client.prepare('insert into TEST.NUMBERS values (?, ?)', function(err, statement){
if (err) return console.error('Error:', err);
// Each inner array represents one row
const data = [[1, 'one'], ['2', 'two'], [3, 'three']];
statement.exec(data, function(err, affectedRows) {
if (err) return console.error('Error:', err);
console.log('Rows affected:', affectedRows);
});
});
client.prepare('insert into TEST.NUMBERS values (?, ?)', function(err, statement){
if (err) {
return console.error('Prepare error:', err);
}
statement.exec([[1, 'one'], ['2', 'two'], [3, 'three']], function(err, affectedRows) {
if (err) {
return console.error('Exec error:', err);
}
console.log('Array of affected rows:', affectedRows);
});
});