Databases Reference
In-Depth Information
5.12.5 Savepoints
A savepoint can be created in an SQLj program using universal driver. A
savepoint in an SQLj program can be created using the SAVEPOINT statement.
Example 5-33 shows how to create a savepoint in an SQLj program.
Example 5-33 Creating a savepoint in SQLj
con.setAutoCommit(false);
ctx ctx1=new ctx(con);
#sql[ctx1] {create table order(id int, description varchar(100)) };
#sql[ctx1] {insert into order values(1, 'first order of the day')};
#sql[ctx1] {SAVEPOINT SVPT1 ON ROLLBACK RETAIN CURSORS};
#sql[ctx1] {insert into order values(2, 'second order')};
#sql[ctx1] {SAVEPOINT SVPT2 ON ROLLBACK RETAIN CURSORS};
#sql[ctx1] {insert into order values(3, 'third order')};
#sql[ctx1] {ROLLBACK TO SAVEPOINT SVPT2};
#sql[ctx1] {RELEASE SAVEPOINT SVPT1};
#sql[ctx1] {commit};
5.12.6 XQuery and SQL/XML support
An XQuery can only be run dynamically. As SQLj runs every query statically, to
run the XQuery in SQLj, we need to change the XQuery statement into an
SQL/XML statement. An SQL/XML statement can be run statically. For example,
the SQL/XML equivalent of query in Example 2-11 on page 71 is shown in
Example 5-34.
Example 5-34 SQL/XML equivalent of XQuery statement
select xmlquery('$d/movie[movie-details/country="US"]/heading/title'
passing movies.info as "d") from movies
Example 5-35 shows the SQLj code to run the query shown in Example 5-34.
Example 5-35 Running XQuery in SQLj
#sql custIter = {select
xmlquery('$d/movie[movie-details/country="US"]/heading/title' passing
movies.info as "d") from movies};
For retrieving XML values, an iterator can be defined either with Object data type
argument or a new class, com.ibm.db2.jcc.DB2Xml object.
Search WWH ::




Custom Search