Informix JDBC Driver Programmer's Guide
Chapter 2: Programming with Informix JDBC Driver
Contents
Index
Handling Transactions
By default, all new
Connection
objects are in autocommit mode. This means that a
COMMIT
statement is automatically executed after each statement that is sent to the database server. To turn autocommit mode off for a connection, explicitly call the
Connection.setAutoCommit(false)
method.
When autocommit mode is off, Informix JDBC Driver implicitly starts a new transaction when the next statement is sent to the database server. This transaction lasts until the user issues a
COMMIT
or
ROLLBACK
statement. If the user has already started a transaction by executing
setAutoCommit(false)
, and then calls
setAutoCommit(false)
again, the existing transction continues unchanged. It is the responsibility of the Java program to explicitly terminate the transaction by issuing either a
COMMIT
or a
ROLLBACK
statement before it drops the connection to the database or the database server.
If the Java program sets autocommit mode on while inside a transaction, Informix JDBC Driver rolls back the current transaction before it actually turns autocommit mode on.
In a database that has been created with logging, if a
COMMIT
statement is sent to the database server (either with the
Connection.commit()
method or directly with an
SQL
statement) and autocommit mode is on, the error
-255 : Not in transaction
is returned by the database server because there is currently no user transaction started.
In a database created in
ANSI
mode, explicitly sending a
COMMIT
statement to the database server is a no-op. No error is returned because the database server automatically starts a transaction before it executes the statement if there is no user transaction currently open. The
COMMIT
statement therefore just commits an empty transaction.
Informix JDBC Driver Programmer's Guide
, Version 1.22
Copyright © 1998, Informix Software, Inc. All rights reserved.