IBM DB2 Manual page 163

Table of Contents

Advertisement

v If the data source is DB2 Database for Linux, UNIX, and Windows, the data
source generates an error if the external and internal encoding are incompatible,
unless the external and internal encoding are Unicode. If the external and
internal encoding are Unicode, the data source ignores the internal encoding.
v If the data source is DB2 for z/OS, the data source ignores internal encoding.
Character data in XML columns is stored in UTF-8 encoding.
Example: Suppose that you use the following statement to insert data from String
host expression xmlString into an XML column in a table. xmlString is a character
type, so its external encoding is used, whether or not it has an internal encoding
specification.
#sql [ctx] {INSERT INTO CUSTACC VALUES (1, :xmlString)};
Example: Suppose that you copy the data from xmlString into a byte array with
CP500 encoding. The data contains an XML declaration with an encoding
declaration for CP500. Then you insert the data from the byte[] host expression
into an XML column in a table.
byte[] xmlBytes = xmlString.getBytes("CP500");
#sql[ctx] {INSERT INTO CUSTACC VALUES (4, :xmlBytes)};
A byte string is considered to be internally encoded data. The data is converted
from its internal encoding scheme to UTF-8, if necessary, and stored in its
hierarchical format on the data source.
Example: Suppose that you copy the data from xmlString into a byte array with
US-ASCII encoding. Then you construct an sqlj.runtime.AsciiStream host
expression, and insert data from the sqlj.runtime.AsciiStream host expression into
an XML column in a table on a data source.
byte[] b = xmlString.getBytes("US-ASCII");
java.io.ByteArrayInputStream xmlAsciiInputStream =
new java.io.ByteArrayInputStream(b);
sqlj.runtime.AsciiStream sqljXmlAsciiStream =
new sqlj.runtime.AsciiStream(xmlAsciiInputStream, b.length);
#sql[ctx] {INSERT INTO CUSTACC VALUES (4, :sqljXmlAsciiStream)};
sqljXmlAsciiStream is a stream type, so its internal encoding is used. The data is
converted from its internal encoding to UTF-8 encoding and stored in its
hierarchical form on the data source.
Example: sqlj.runtime.CharacterStream host expression: Suppose that you
construct an sqlj.runtime.CharacterStream host expression, and insert data from the
sqlj.runtime.CharacterStream host expression into an XML column in a table.
java.io.StringReader xmlReader =
new java.io.StringReader(xmlString);
sqlj.runtime.CharacterStream sqljXmlCharacterStream =
new sqlj.runtime.CharacterStream(xmlReader, xmlString.length());
#sql [ctx] {INSERT INTO CUSTACC VALUES (4, :sqljXmlCharacterStream)};
sqljXmlCharacterStream is a character type, so its external encoding is used,
whether or not it has an internal encoding specification.
Example: Suppose that you retrieve a document from an XML column into a
java.sql.SQLXML host expression, and insert the data into an XML column in a
table.
Chapter 4. SQLJ application programming
147

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents