Rolling Back a Transaction
Rolling back a transaction is a way to close the transaction explicitly and to discard any database modifications since the transaction was started.
Rolling back an ADO.NET transaction
To roll back a transaction using
ADO.NET, invoke the
Rollback
method on the
Transaction
object:
transaction
.Rollback( );
After rolling back a Transaction
object, the
Dispose
method should be invoked to free any
resources held by the transaction:
transaction
.Dispose( );
Rolling back a JDBC transaction
Invoking the rollback
method on a
JDBC
Connection
object rolls back a transaction within
JDBC and begins a new transaction:
connection
.rollback( );
If the connection is in AUTO COMMIT mode, then a
Java exception will be thrown of SQLException
type.
Get SQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.