Table 22. SQLXML and DB2Xml methods, data types, and added encoding specifications (continued)
Method Output data type Type of XML internal encoding declaration added
SQLXML.getCharacterStream Reader None
SQLXML.getSource Source None
SQLXML.getString String None
DB2Xml.getDB2AsciiStream InputStream None
DB2Xml.getDB2BinaryStream InputStream None
DB2Xml.getDB2Bytes byte[] None
DB2Xml.getDB2CharacterStream Reader None
DB2Xml.getDB2String String None
DB2Xml.getDB2XmlAsciiStream InputStream US-ASCII
DB2Xml.getDB2XmlBinaryStream InputStream Specified by getDB2XmlBinaryStream targetEncoding
parameter
DB2Xml.getDB2XmlBytes byte[] Specified by DB2Xml.getDB2XmlBytes targetEncoding
parameter
DB2Xml.getDB2XmlCharacterStream Reader ISO-10646-UCS-2
DB2Xml.getDB2XmlString String ISO-10646-UCS-2
If the application executes the XMLSERIALIZE function on the data that is to be
returned, after execution of the function, the data has the data type that is specified
in the XMLSERIALIZE function, not the XML data type. Therefore, the driver
handles the data as the specified type and ignores any internal encoding
declarations.
Example: Suppose that you retrieve data from an XML column into a String host
expression.
#sql iterator XmlStringIter (int, String);
#sql [ctx] siter = {SELECT C1, CADOC from CUSTACC};
#sql {FETCH :siter INTO :row, :outString};
The String type is a character type, so the data is converted from UTF-8 to the
external encoding, which is the default JVM encoding, and returned without any
XML declaration.
Example: Suppose that you retrieve data from an XML column into a byte[] host
expression.
#sql iterator XmlByteArrayIter (int, byte[]);
XmlByteArrayIter biter = null;
#sql [ctx] biter = {SELECT c1, CADOC from CUSTACC};
#sql {FETCH :biter INTO :row, :outBytes};
The byte[] type is a binary type, so no data conversion from UTF-8 encoding
occurs, and the data is returned without any XML declaration.
Example: Suppose that you retrieve a document from an XML column into a
java.sql.SQLXML host expression, but you need the data in a binary stream.
#sql iterator SqlXmlIter (int, java.sql.SQLXML);
SqlXmlIter SQLXMLiter = null;
java.sql.SQLXML outSqlXml = null;
#sql [ctx] SqlXmlIter = {SELECT c1, CADOC from CUSTACC};
#sql {FETCH :SqlXmlIter INTO :row, :outSqlXml};
java.io.InputStream XmlStream = outSqlXml.getBinaryStream();
Chapter 4. SQLJ application programming 149