A transaction is a logical unit of work. To complete a logical unit of work, several actions may have to be taken against a database.
Transactional support allows applications to ensure the following:
Transactions are used to provide data integrity, correct application semantics, and a consistent view of data during concurrent access. All Java™ Database Connectivity (JDBC) compliant drivers must support transactions.
All transactional work is handled at the Connection object level. When the work for a transaction completes, it can be finalized by calling the commit method. If the application aborts the transaction, the rollback method is called.
All Statement objects under a connection are a part of the transaction. This means is that if an application creates three Statement objects and uses each object to make changes to the database, when a commit or rollback call happens, the work for all three statements either becomes permanent or is discarded.
The commit and rollback SQL statements are used to finalize transactions when working purely with SQL. These SQL statements cannot be dynamically prepared and you should not attempt to use them in your JDBC applications to complete transactions.