EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #161 background imageLoading...
Page #161 background image
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.
#sql context Ctx; // Create connection context class Ctx
String empNumVar;
int shoeSizeVar;
...
try { // Load the JDBC driver
Class.forName("com.ibm.db2.jcc.DB2Driver");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection jdbccon=
DriverManager.getConnection("jdbc:db2://sysmvs1.stl.ibm.com:5021/NEWYORK",
userid,password);
// Create JDBC connection object jdbccon
jdbccon.setAutoCommit(false); // Do not autocommit
Ctx ctxt=new Ctx(jdbccon);
// Create connection context object myConnCtx
// for the connection to NEWYORK
... // Perform some SQL
#sql [ctxt] {COMMIT}; // Commit the transaction
// Commit the create
#sql [ctxt]
{INSERT INTO EMP_SHOE VALUES ('000010', 6)};
// Insert a row
#sql [ctxt]
{SAVEPOINT SVPT1 ON ROLLBACK RETAIN CURSORS};
// Create a savepoint
...
#sql [ctxt]
{INSERT INTO EMP_SHOE VALUES ('000020', 10)};
// Insert another row
#sql [ctxt] {ROLLBACK TO SAVEPOINT SVPT1};
// Roll back work to the point
// after the first insert
...
#sql [ctxt] {RELEASE SAVEPOINT SVPT1};
// Release the savepoint
ctx.close(); // Close the connection context
Related tasks
“Committing or rolling back SQLJ transactions” on page 153
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.
Figure 51. Setting, rolling back to, and releasing a savepoint in an SQLJ application
Chapter 4. SQLJ application programming 145

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability