View RSS Feed

JDBC

Batch Updates and Transactions

Rate this Entry
by , 04-27-2012 at 07:18 PM (1699 Views)
It is important to keep in mind, that each update added to a Statement or PreparedStatement is executed separately by the database. That means, that some of them may succeed before one of them fails. All the statements that have succeeded are now applied to the database, but the rest of the updates may not be. This can result in an inconsistent data in the database.

To avoid this, you can execute the batch update inside a transaction. When executed inside a transaction you can make sure that either all updates are executed, or none are. Any successful updates can be rolled back, in case one of the updates fail.

Submit "Batch Updates and Transactions" to Facebook Submit "Batch Updates and Transactions" to Digg Submit "Batch Updates and Transactions" to del.icio.us Submit "Batch Updates and Transactions" to StumbleUpon Submit "Batch Updates and Transactions" to Google

Comments