beginTransaction()

Begins an explicit transaction for the current connection.

Syntax

void beginTransaction()
 

Parameters

None.

Return values

None.

Exceptions

CwDBConnectionException - If a database error occurs.

Notes

The beginTransaction() method marks the beginning of a new explicit transaction in the current connection. The beginTransaction(), commit() and rollBack() methods together provide management of transaction boundaries for an explicit transaction. This transaction contains SQL queries, which include the SQL statements INSERT, DELETE, or UPDATE, and a stored procedure that includes one of these SQL statements.

If you do not use beginTransaction() to specify the beginning of the explicit transaction, the database executes each SQL statement as a separate transaction.

Important:
Only use beginTransaction() if the connection uses explicit transaction bracketing. If the connection uses implicit transaction bracketing, use of beginTransaction() results in a CwDBTransactionException exception.

Before beginning an explicit transaction, you must create a CwDBConnection object with the getDBConnection() method from the BaseDLM class. Make sure that this connection uses explicit transaction bracketing.

Examples

The following example uses a transaction to execute a query for inserting rows into a table in the database associated with connections in the CustDBConnPool.

CwDBConnection connection = getDBConnection("CustDBConnPool", false);
  
 // Begin a transaction
 connection.beginTransaction();
  
 // Insert a row
 connection.executeSQL("insert...");
  
 // Commit the transaction
 connection.commit();
  
 // Release the connection
 connection.release();
 

See also

commit(), getDBConnection(), inTransaction(), rollBack()

Copyright IBM Corp. 1997, 2003