Savepoints In Sqlj Applications; Xml Data In Sqlj Applications - IBM DB2 Manual

Table of Contents

Advertisement

Savepoints in SQLJ applications

Under the IBM Data Server Driver for JDBC and SQLJ, you can include any form
of the SQL SAVEPOINT statement in your SQLJ program.
An SQL savepoint represents the state of data and schemas at a particular point in
time within a unit of work. SQL statements exist to set a savepoint, release a
savepoint, and restore data and schemas to the state that the savepoint represents.
The following example demonstrates how to set a savepoint, roll back to the
savepoint, and release the savepoint.
Figure 51. Setting, rolling back to, and releasing a savepoint in an SQLJ application
#sql context Ctx;
String empNumVar;
int shoeSizeVar;
...
try {
}
catch (ClassNotFoundException e) {
}
Connection jdbccon=
jdbccon.setAutoCommit(false); // Do not autocommit
Ctx ctxt=new Ctx(jdbccon);
...
#sql [ctxt] {COMMIT};
#sql [ctxt]
#sql [ctxt]
...
#sql [ctxt]
#sql [ctxt] {ROLLBACK TO SAVEPOINT SVPT1};
...
#sql [ctxt] {RELEASE SAVEPOINT SVPT1};
ctx.close();

XML data in SQLJ applications

In SQLJ applications, you can store data in XML columns and retrieve data from
XML columns.
In DB2 tables, the XML built-in data type is used to store XML data in a column as
a structured set of nodes in a tree format.
Class.forName("com.ibm.db2.jcc.DB2Driver");
e.printStackTrace();
DriverManager.getConnection("jdbc:db2://sysmvs1.stl.ibm.com:5021/NEWYORK",
userid,password);
{INSERT INTO EMP_SHOE VALUES ('000010', 6)};
{SAVEPOINT SVPT1 ON ROLLBACK RETAIN CURSORS};
{INSERT INTO EMP_SHOE VALUES ('000020', 10)};
Related tasks
"Committing or rolling back SQLJ transactions" on page 153
// Create connection context class Ctx
// Load the JDBC driver
// Create JDBC connection object jdbccon
// Create connection context object myConnCtx
// for the connection to NEWYORK
// Perform some SQL
// Commit the transaction
// Commit the create
// Insert a row
// Create a savepoint
// Insert another row
// Roll back work to the point
// after the first insert
// Release the savepoint
// Close the connection context
Chapter 4. SQLJ application programming
145

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents