Xmlcast In Sqlj Applications; Sqlj Utilization Of Sdk For Java Version 5 Function - IBM DB2 Manual

Table of Contents

Advertisement

XMLCAST in SQLJ applications

|
|
|
|
|
|
|
|
|
|
|
|
|

SQLJ utilization of SDK for Java Version 5 function

150
Application Programming Guide and Reference for Java
The FETCH statement retrieves the data into the SQLXML object in UTF-8
encoding. The SQLXML.getBinaryStream stores the data in a binary stream.
Example: Suppose that you retrieve a document from an XML column into a
com.ibm.db2.jcc.DB2Xml host expression, but you need the data in a byte string
with an XML declaration that includes an internal encoding specification for
UTF-8.
#sql iterator DB2XmlIter (int, com.ibm.db2.jcc.DB2Xml);
DB2XmlIter db2xmliter = null;
com.ibm.db2.jcc.DB2Xml outDB2Xml = null;
#sql [ctx] db2xmliter = {SELECT c1, CADOC from CUSTACC};
#sql {FETCH :db2xmliter INTO :row, :outDB2Xml};
byte[] byteArray = outDB2XML.getDB2XmlBytes("UTF-8");
The FETCH statement retrieves the data into the DB2Xml object in UTF-8
encoding. The getDB2XmlBytes method with the UTF-8 argument adds an XML
declaration with a UTF-8 encoding specification and stores the data in a byte array.
Related concepts
"XML data in SQLJ applications" on page 145
Related reference
"DB2Xml interface" on page 368
Before you can use XMLCAST to cast a host variable to the XML data type in an
SQLJ application, you need to cast the host variable to the corresponding SQL data
type.
Example: The following code demonstrates a situation in which it is necessary to
cast a String host variable to an SQL character type, such as VARCHAR, before
you use XMLCAST to cast the value to the XML data type.
String xmlresult = null;
String varchar_hv = "San Jose";
...
#sql [con] {SELECT XMLCAST(CAST(:varchar_hv AS VARCHAR(32)) AS XML) INTO
:xmlresult FROM SYSIBM.SYSDUMMY1};
Your SQLJ applications can use a number of functions that were introduced with
the SDK for Java Version 5.
Static import
The static import construct lets you access static members without qualifying those
members with the name of the class to which they belong. For SQLJ applications,
this means that you can use static members in host expressions without qualifying
them.
Example: Suppose that you want to declare a host expression of this form:
double r = cos(PI * E);
cos, PI, and E are members of the java.lang.Math class. To declare r without
explicitly qualifying cos, PI, and E, include the following static import statement in
your program:
import static java.lang.Math.*;

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents