SQL/MX Programming Manual for Java
SQL/MX Programming Considerations
HP NonStop SQL/MX Programming Manual for Java—523726-003
4-43
Setting Attributes for Transactions
Setting Attributes for Transactions
Use a SET TRANSACTION statement to set some of the attributes for subsequent
transactions. When coding a SET TRANSACTION statement in an SQLJ program,
consider that:
•
The READ ONLY access mode has no effect on the behavior of a transaction in an
SQLJ program.
•
The diagnostics area does not apply to SQLJ programs and is disallowed in a SET
TRANSACTION statement in an SQLJ program.
•
Special considerations exist for setting the isolation level.
To set attributes for transactions in an SQLJ program, see:
•
Autocommit Setting on page 4-43
•
Isolation Level Setting on page 4-44
•
Default Transaction Attributes on page 4-45
Autocommit Setting
The autocommit setting specifies whether an implicit transaction commits automatically
at the end of statement execution or rolls back automatically if an error occurs. When
autocommit is enabled (that is, turned on), each implicit transaction commits
automatically at the end of statement execution.
The BEGIN WORK statement turns off the autocommit setting inside an explicit, user-
defined transaction. Even if you turn on the autocommit setting before an explicit
transaction starts, you must code a COMMIT WORK statement to commit the
transaction.
Turn off autocommit if you do not want implicit transactions of subsequent statements
outside explicit transactions to commit automatically. Otherwise, turn on autocommit.
Because the autocommit attribute of a JDBC connection is enabled by default and
SQLJ programs use JDBC connections, the autocommit setting of SQLJ programs is
enabled by default.
In an SQLJ program, turn autocommit on or off by using one of these approaches:
•
Specifying the AUTOCOMMIT option in a SET TRANSACTION statement:
#sql {SET TRANSACTION AUTOCOMMIT OFF};
For more information, see the SQL/MX Reference Manual.
•
Passing a Boolean value to the autoCommit argument of a URL connection
context constructor:
SQLMXCtx ctx = new SQLMXCtx("jdbc:sqlmx:", false);
In this example, the autocommit setting applies to all implicit transactions
associated with the connection context ctx. For more information, see Connection
Contexts on page 3-8.