I have a java program that in some circumstances must update a large amount of records in a database (e.g 100,000).
The way it does it is by creating a PreparedStatement
and by using the addBatch
technique.
Here is the snippet:
connection.setAutoCommit(false);
PreparedStatement ps = connection.prepareStatement(
"UPDATE myTable SET colName=? where id=?");
for (...) { // this loop can be 100000 long
colValue = ...
id = ...
ps.setString(1,colValue);
ps.setString(2,id);
ps.addBatch();
}
ps.executeBatch();
connection.commit();
is this the best (fastest) way to update 100000 of records in JDBC ?
Could anybody suggest a better way ?