Xml Data Retrieval In Sqlj Applications - IBM DB2 Manual

Table of Contents

Advertisement

java.sql.ResultSet rs = s.executeQuery ("SELECT * FROM CUSTACC");
rs.next();
java.sql.SQLXML xmlObject = (java.sql.SQLXML)rs.getObject(2);
#sql [ctx] {INSERT INTO CUSTACC VALUES (6, :xmlObject)};
After you retrieve the data it is still in UTF-8 encoding, so when you insert the
data into another XML column, no conversion occurs.
Example: Suppose that you retrieve a document from an XML column into a
com.ibm.db2.jcc.DB2Xml host expression, and insert the data into an XML column
in a table.
java.sql.ResultSet rs = s.executeQuery ("SELECT * FROM CUSTACC");
rs.next();
com.ibm.db2.jcc.DB2Xml xmlObject = (com.ibm.db2.jcc.DB2Xml)rs.getObject(2);
#sql [ctx] {INSERT INTO CUSTACC VALUES (6, :xmlObject)};
After you retrieve the data it is still in UTF-8 encoding, so when you insert the
data into another XML column, no conversion occurs.

XML data retrieval in SQLJ applications

When you retrieve data from XML columns of a database table in an SQLJ
application, the output data must be explicitly or implicitly serialized.
The host expression or iterator data types that you can use to retrieve data from
XML columns are:
v java.sql.SQLXML (requires an SDK for Java Version 6 or later, and the IBM Data
v com.ibm.db2.jcc.DB2Xml (deprecated)
v String
v byte[]
v sqlj.runtime.AsciiStream
v sqlj.runtime.BinaryStream
v sqlj.runtime.CharacterStream
If the application does not call the XMLSERIALIZE function before data retrieval,
the data is converted from UTF-8 to the external application encoding for the
character data types, or the internal encoding for the binary data types. No XML
declaration is added. If the host expression is an object of the java.sql.SQLXML or
com.ibm.db2.jcc.DB2Xml type, you need to call an additional method to retrieve
the data from this object. The method that you call determines the encoding of the
output data and whether an XML declaration with an encoding specification is
added.
The following table lists the methods that you can call to retrieve data from a
java.sql.SQLXML or a com.ibm.db2.jcc.DB2Xml object, and the corresponding
output data types and type of encoding in the XML declarations.
Table 22. SQLXML and DB2Xml methods, data types, and added encoding specifications
Method
SQLXML.getBinaryStream
148
Application Programming Guide and Reference for Java
Related concepts
"XML data in SQLJ applications" on page 145
Related reference
"DB2Xml interface" on page 368
Server Driver for JDBC and SQLJ version 4.0 or later)
Output data type
InputStream
Type of XML internal encoding declaration added
None

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents