Committing a Transaction
Committing a transaction is a way to explicitly close the transaction and make its database modifications permanent.
Committing an ADO.NET transaction
To commit a transaction using
ADO.NET, invoke the
Commit
method on the
Transaction
object:
transaction
.Commit( );
ADO.NET is more object-oriented than many database-programming APIs,
as can be seen from the encapsulation of a transaction into a unique
object type. This has the drawback of making the methods for
explicitly ending a transaction more difficult to find than those to
begin a transaction, since they are on different object types.
Remember that the method to begin a transaction is on the
Connection
object, and the methods to commit or
roll back a transaction are found on the
Transaction
object.
Committing a JDBC transaction
Invoking the commit
method on a
JDBC
Connection
object commits a transaction within
JDBC and begins a new transaction:
connection
.commit( );
If the connection is in AUTO COMMIT mode, you
will then get a Java exception of type
SQLException
because the connection will not have
a pending transaction.
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.