SQL/MX Programming Manual for Java
SQL/MX Programming Considerations
HP NonStop SQL/MX Programming Manual for Java—523726-003
4-41
Transaction Management
Transaction Management
A transaction, which is a set of database changes that must be completed as a group,
is the basic recoverable unit in case of a failure or transaction interruption. You can
define transactions in an SQLJ program in much the same way you would define them
in an embedded SQL program in C or COBOL. The typical order of events is:
1. Transaction is started.
2. Database changes are made.
3. Transaction is committed if the database changes are made successfully.
If the transaction cannot successfully make the changes or if you do not want to
complete the transaction, you can abort the transaction and roll the database back to
its original state.
This subsection describes:
•
Transaction Control Statements on page 4-41
•
Steps for Ensuring Data Consistency on page 4-42
For more information about transaction management, see the SQL/MX Reference
Manual.
Transaction Control Statements
Control the transactions in an SQLJ program by specifying these SQL/MX statements
as SQLJ executable clauses in the source file:
•
BEGIN WORK statement
•
COMMIT WORK statement
•
ROLLBACK WORK statement
•
SET TRANSACTION statement
For the syntax of these statements, see the SQL/MX Reference Manual. To use these
transaction control statements in an SQLJ program, see Steps for Ensuring Data
Consistency on page 4-42.
The jdbcmx.transactionMode property might affect transaction control statements
in an SQLJ program. If you specify the internal transaction mode of the
jdbcmx.transactionMode property, it causes an external transaction to be
suspended and an embedded SQL statement to be executed in an internal JDBC-
managed transaction. If you specify the external transaction mode, an external
transaction must be present for a transaction to occur. In the default mixed transaction
mode, if you do not specify transaction control statements in an SQLJ program, the
JDBC/MX driver handles transaction management. For more information, see the
JDBC Driver for SQL/MX Programmer’s Reference.
Note. If you plan to register a method in an SQLJ program as an SPJ, be aware that SQL/MX
does not support SQL transaction statements or JDBC transaction methods in an SPJ method.
For more information, see the SQL/MX Guide to Stored Procedures in Java.