Chapter 7. Using XML with Java 133
latest level. This driver provides the SQLXML interface and also support other DB2 features
such as binary XML format. You have more flexibility in coding your application and better
performance.
7.1.1 XML support in JDBC 3.0
When developing applications with JDBC3.0, you can use the Java standard interface,
ResultSet, to retrieve XML data from DB2 tables. This interface provides getter methods for
retrieving XML column values from the current row. Table 7-2 summarizes the methods in the
ResultSet interface.
Table 7-2 JDBC 3.0 Getter methods of ResultSet
The getObject method retrieves XML data into an object of type DB2Xml, which provides
more getter methods. The com.ibm.db2.jcc.DB2Xml object supports the methods that are
listed in Table 7-3.
Table 7-3 DB2Xml getter methods
Getter methods of
ResultSet
Description
getBytes Retrieves the value of the designated column in the current row of this
ResultSet object as UTF-8 encoded bytes.
getString Retrieves the value of the designated column in the current row of this
ResultSet object as a string in the Java programming language.
getAsciiStream Retrieves the value of the designated column in the current row of this
ResultSet object as a stream of ASCII characters.
getBinaryStream Retrieves the value of the designated column in the current row of this
ResultSet object as a UTF-8 encoded binary stream.
getCharacterStream Retrieves the value of the designated column in the current row of this
ResultSet object as a java.io.Reader object.
getObject Retrieves the value of the designated column in the current row of this
ResultSet object as a com.ibm.db2.jcc.DB2Xml object.
Note: The methods in Table 7-2 do not add an encoding declaration to the retrieved XML
data.
DB2Xml getter methods Description
getDB2Bytes() Retrieves the value of the designated column in the current row of
this ResultSet object as UTF-8 encoded bytes.
getDB2XmlBytes() Retrieves the value of the designated column in the current row of
this ResultSet object as a byte array in the Java programming
language. The method converts the bytes to the target encoding
and adds XML declaration with encoding tag.
getDB2String() Retrieves the value of the designated column in the current row of
this ResultSet object as a string in the Java programming
language.
134 Extremely pureXML in DB2 10 for z/OS
The getDB2XmlXXX methods generate XML declarations with an encoding attribute for the
retrieved XML data. For example, the getDB2String() and getDB2XmlString() methods return
the XML data in the same encoding, USC-2, however the latter adds the appropriate
encoding declaration to the XML document.
In a JDBC application, you can update or insert data into XML columns of a table at a DB2
data server using one of the setter methods of the PreparedStatement interface.
The following setXXX methods are supported against XML columns in JDBC 3.0:
setAsciiStream()
setBinaryStream()
setBlob()
setBytes()
setCharacterStream()
setClob()
setString()
setObject()
This method supports DB2Xml, String, byte[], InputStream, Reader, CLOB, and BLOB as
parameters.
getDB2XmlString() Retrieves the value of the designated column in the current row of
this ResultSet object as a string in the Java programming
language. The method adds an XML declaration with the
"ISO-10646-UCS-2" encoding tag.
getDB2AsciiStream() Retrieves the value of the designated column in the current row of
this ResultSet object as a stream of ASCII characters.
getDB2XmlAsciiStream() Retrieves the value of the designated column in the current row of
this ResultSet object as a stream of ASCII characters. The method
will add XML declaration with encoding tag
getDB2BinaryStream() Retrieves the value of the designated column in the current row of
this ResultSet object as a UTF-8 encoded binary stream.
getDB2XmlBinaryStream() Retrieves the value of the designated column in the current row of
this ResultSet object as a binary stream. The method converts the
bytes to the target encoding and adds the XML declaration with
encoding tag.
getDB2CharacterStream() Retrieves the value of the designated column in the current row of
this ResultSet object as a java.io.Reader object
getDB2XmlCharacterStream() Retrieves the value of the designated column in the current row of
this ResultSet object as a java.io.Reader object. The method
adds an XML declaration with "ISO-10646-UCS-2" encoding tag.
DB2Xml getter methods Description

Get Extremely pureXML in DB2 10 for z/OS now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.