IBM DB2 Manual page 82

Table of Contents

Advertisement

as internally encoded data. XML data that is sent to the data source as character
data is treated as externally encoded data.
External encoding for Java applications is always Unicode encoding.
Externally encoded data can have internal encoding. That is, the data might be sent
to the data source as character data, but the data contains encoding information.
The data source handles incompatibilities between internal and external encoding
as follows:
v If the data source is DB2 Database for Linux, UNIX, and Windows, the database
v If the database source is DB2 for z/OS, the database source ignores the internal
Character data in XML columns is stored in UTF-8 encoding. The database source
handles conversion of the data from its internal or external encoding to UTF-8.
Example: The following example demonstrates inserting data from an SQLXML
object into an XML column. The data is String data, so the database source treats
the data as externally encoded.
66
Application Programming Guide and Reference for Java
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 database source ignores the internal
encoding.
encoding.
public void insertSQLXML()
{
Connection con = DriverManager.getConnection(url);
SQLXML info = con.createSQLXML;
PreparedStatement insertStmt = null;
String infoData =
"<customerinfo xmlns=""http://posample.org"" " +
"Cid=""1000"" xmlns=""http://posample.org"">...</customerinfo>";
cid.setString(cidData);
int cid = 1000;
try {
sqls = "INSERT INTO CUSTOMER (CID, INFO) VALUES (?, ?)";
insertStmt = con.prepareStatement(sqls);
insertStmt.setInt(1, cid);
insertStmt.setSQLXML(2, info);
// to an input parameter
if (insertStmt.executeUpdate() != 1) {
System.out.println("insertSQLXML: No record inserted.");
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}
catch (SQLException sqle) {
System.out.println("insertSQLXML: SQL Exception: " +
sqle.getMessage());
System.out.println("insertSQLXML: SQL State: " +
sqle.getSQLState());
System.out.println("insertSQLXML: SQL Error Code: " +
sqle.getErrorCode());
}
}
// Create an SQLXML object
// Populate the SQLXML object
// Assign the SQLXML object value

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents