Databases Reference
In-Depth Information
the text indexes easily either using command line tools or through DB2 control
center.
2.2.11 Application support (interfaces)
The new XML data type requires existing application interfaces to recognize it.
The major database programming interfaces, including Java and PHP, have
been enabled and optimized to make use of DB2 XML data type. The XML is
stored natively in pure hierarchical form; however, the data type has been
externalized to the application interfaces as a serialized XML string. By default,
all XML data accessed through the application interfaces is returned with an XML
declaration, including an encoding attribute. The application can override this
default code set if required. All of the major database interfaces support the XML
data type as XML, not as a character type. This also avoids unwanted and
unnecessary code page conversion. In this section, we briefly discuss various
database programming interfaces supported by XML. This book is all about
application development using various interfaces, so you can select a chapter of
your interest for further reading.
JDBC
.JDBC or Java database connectivity layer has been enhanced to make XML
data compatible with strings, byte arrays, and streams, so that columns and
parameters can be bound to any of these types. Standardizing a JDBC XML type
is a work in progress, but a proprietary XML type com.ibm.db2.DB2Xml is
available right now. This interface provides a number of methods that make
application development with XML easy. Look at the code in Example 2-23.
Example 2-23 JDBC with XML
String sql = "SELECT ID, MOVIEDETAILS from MOVIES where ID = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, "345”);
ResultSet resultSet = stmt.executeQuery();
String xml = resultSet.getString("MOVIEDETAILS"); // or
InputStream inputStream = resultSet.getBinaryStream("MOVIEDETAILS");
// or
Reader reader = resultSet.getCharacterStream("MOVIEDETAILS"); // or
DB2Xml db2xml = (DB2Xml) resultSet.getObject("MOVIEDETAILS");
Search WWH ::




Custom Search