Making the Most of JDBC with WebRowSet

Making the Most of JDBC with WebRowSet

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();

wrs.populate(rs);

try {

  wrs.writeXml(

  new FileOutputStream("student.xml"));

} catch (FileNotFoundException e) {

  e.printStackTrace();

} catch (IOException e) {

  e.printStackTrace();

}

... ... ...

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=

 "http://java.sun.com/xml/ns/jdbc" 

xmlns:xsi=

 "http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation=

 "http://java.sun.com/xml/ns/jdbc 

http://java.sun.com/xml/ns/jdbc/webrowset.xsd"> 

 < properties> 

... ... ... 

 </properties> 

 <metadata> 

       ... ... ...

 </metadata> 

 <data> 

... ... ...

</data> 

</webRowSet>

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.

 <data>

   <currentRow>

     <columnValue>200 < /columnValue>

     <columnValue>Jack</columnValue>

     <columnValue>Dakota</columnValue>

     <columnValue>21</columnValue>

   </currentRow>

   <currentRow>

     <columnValue>100</columnValue>

     <columnValue>John</columnValue>

     <columnValue>Doe</columnValue>

     <columnValue>26</columnValue>

   </currentRow>

 </data>

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.

Prev  [1] [2] [3] [4] [5] Next

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > JDOnJDBCnSQLJ > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction