JDBC Batch Updates
kotlin java
JDBC Batch Updates
val dataSource: DataSource = DataSourceFactory.of(env = env, service = service)
DriverManager.getConnection(dataSource.url, dataSource.user, dataSource.pw)
.use { connection ->
connection.autoCommit = false
try {
// QUERY: UPDATE vehicle SET vehicle_id=? WHERE vehicle_id=?
val ps: PreparedStatement = connection.prepareStatement(QUERY)
for(id in VEHICLE_IDS) {
ps.setString(1, vehicleId.next)
ps.setString(2, vehicleId.prev)
ps.addBatch()
}
val result: IntArray = ps.executeBatch()
println("#[Result] ${result.contentToString()}")
connection.commit()
} catch (e: Exception) {
connection.rollback()
}
}