Manipulating XML Data in Java applications
XML, as a built-in data type, was introduced in DB2 9.1. XQuery is the language which is used to query XML data, just as SQL is used to query relational data. Apart from using XQuery, DB2 also provides SQLXML and XMLSQL functions that allow us to query the XML data by using SQL queries and vice versa. Like any SQL statement, XQuery can also be embedded in any host language. In this recipe, we will discuss how we can use XML data in Java applications.
Getting ready
We need the IBM Data Server for the JDBC and SQLJ installed. This driver is shipped as part of DB2.
How to do it...
1. Retrieving XML Data: XML data can be retrieved in several Java forms such as XML, Object, String, Reader, InputStream, and so on. XML can be retrieved by methods available in the
ResultSet
class.PreparedStatement selectStmt = con.prepareStatement("SELECT info FROM customer WHERE cid = 1000"); ResultSet rs = selectStmt.executeQuery();
Once we have the result set, we can...