Databases Reference
In-Depth Information
Example 5-23 Savepoint
con.setAutoCommit(false);
Statement stmt=con.createStatement();
stmt.executeUpdate("create table order(id int, description
varchar(100))");
con.commit();
stmt.executeUpdate("insert into order values(1, 'first order of the
day')");
Savepoint svpt1=con.setSavepoint();
stmt.executeUpdate("insert into order values(2, 'second order')");
Savepoint svpt2=con.setSavepoint();
stmt.executeUpdate("insert into order values(3, 'third order')");
con.rollback(svpt2);
con.releaseSavepoint(svpt1);
stmt.close();
con.commit();
5.11 SQL/XML and XQuery support
An XQuery or SQL/XML statement can be executed in the same manner as we
execute an SQL statement in the JDBC application. All the restrictions of XQuery
are also applicable here. For the XQuery statement, the query should be prefixed
with the xquery word.
For more details about how to write an XQuery, refer to Chapter 2, “Application
development with DB2 pureXML” on page 49.
Example 5-24 shows how to run an XQuery statement in Java. This XQuery
gives all the customers' cities in Canada.
Example 5-24 Running XQuery
Statement stmt = con.createStatement();
String query="XQUERY"+
+" declare default element namespace \"http://posample.org\";"+
"fn:distinct-values(db2-fn:xmlcolumn('CUSTOMER.INFO')"+\";"+
"/customerinfo/addr[@country=\"Canada\"]/city)";
System.out.println();
System.out.println(query);
ResultSet rs = stmt.executeQuery(query);
// retrieve and display the result from the query
while (rs.next())
{
Search WWH ::




Custom Search