The commit() and rollback() methods are used in JDBC to manage database transactions. A transaction is a group of database operations that should be treated as a single unit of work. The commit() method permanently saves all changes made during the current transaction, while rollback() cancels the changes made since the transaction began or since the last commit. These methods help maintain data consistency and reliability, especially when multiple operations must either all succeed or all fail. By default, JDBC connections usually use auto-commit mode, where each SQL statement is committed automatically. To manually control transactions, auto-commit can be disabled using setAutoCommit(false).
Transaction Methods
| Method Signature and Short Description |
|---|
|
Enables or disables automatic transaction committing. |
|
Returns whether auto-commit mode is currently enabled. |
|
Permanently saves all changes made during the current transaction. |
|
Cancels all changes made during the current transaction. |
|
Rolls back the transaction to the specified savepoint. |
|
Creates a savepoint at the current position in the transaction. |
|
Creates a named savepoint in the current transaction. |
|
Removes a previously created savepoint. |
