[ Team LiB ] Previous Section Next Section

18.5 Atomic Transactions

By default, a newly created database Connection object is in auto-commit mode. That means that each update to the database is treated as a separate transaction and is automatically committed to the database. Sometimes, however, you want to group several updates into a single atomic transaction, with the property that either all the updates complete successfully or no updates occur at all. With a database system (and JDBC driver) that supports it, you can take the Connection out of auto-commit mode and explicitly call commit( ) to commit a batch of transactions or call rollback( ) to abort a batch of transactions, undoing the ones that have already been done. Example 21-3 in Chapter 21 uses atomic transactions to ensure database consistency.

    [ Team LiB ] Previous Section Next Section