ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Making the Most of JDBC with WebRowSet
Pages: 1, 2, 3, 4, 5

Exporting ResultSet

Let me now take this example bit further by assuming that this program is part of an application that requires data conversion from database to XML for some further processing. I will use implementation class com.sun.rowset.WebRowSetImpl for this purpose. To see this in action, let's add some code to construct an instance of javax.sql.rowset.WebRowSet and export the result set to XML file. Here's how you do this:

... ... ... 
ResultSet rs = 
  stmt.executeQuery("select * from student");
WebRowSet wrs = new WebRowSetImpl();
try {
  new FileOutputStream("student.xml"));
} catch (FileNotFoundException e) {
} catch (IOException e) {
... ... ...

The output from wrs.writeXML() results in an XML document that conforms to the WebRowSet schema definition. It contains three parts: properties, metadata and data. The general layout is below; see the resources section for the complete output file.

<?xml version="1.0"?> 
<webRowSet xmlns=
 < properties> 
... ... ... 
       ... ... ...
... ... ...

The <properties> tag provides details of the synchronization provider, such as isolation level, RowSet type, etc. The <metadata> tag provides information about the underlying database table, such as numbers, name, and type of columns, etc. The <data> tag holds actual data that has following information for the table above.

     <columnValue>200 < /columnValue>

The <currentRow> tag in the above example shows the values of each column for the WebRowSet object currently mapped to an underlying data source without any modification. Any data manipulation operations such as insert, update, or delete are marked appropriately in the output XML that I will explain in the next section.

Pages: 1, 2, 3, 4, 5

Next Pagearrow