The Artima Developer Community
Sponsored Link

Java Community News
Making the Most of JDBC with WebRowSet

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Making the Most of JDBC with WebRowSet Posted: Jun 26, 2006 8:47 AM
Reply to this message Reply
Summary
WebRowSet is a JDBC 3 interface that provides not only client-side caching of database query results, but also the ability to expose result elements as XML documents. A recent OnJava article describes how to use WebRowSet in an enterprise application.
Advertisement

The JDBC 3 APIs enriched the JDBC ResultSet interface with several subtypes offering increasingly specialized capabilities. For instance, RowSet provides the ability to move the JDBC cursor backwards in the list of results. CachedRowSet adds sophisticated caching capabilities, including the ability to access results while disconnected from the database, and to update the result set.

WebRowSet, an implementation of which ships as part of Sun's JDK 1.5, enhances CachedRowSet with the capability to expose results as XML documents. In a recent OnJava article, Making the Most of JDBC with WebRowSet, Sharad Acharya describes how to use this new interface, and the resulting XML structure:

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.

In the above example, the actual data is returned in the following format:

<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>

In the article, Acharya suggests that you could use XSLT to transform this result document into some other representation, such as one suitable for display in a JSP page.

While WebRowSet's SQL-to-XML conversion is impressive, the recent rise in the quality and use of object-relational mapping layers seem to provide a cleaner solution. For instance, the Java Persistence API (JPA) can be used apart from EJB 3 and outside an EJB container, and obtaining Java objects as a result of a query performed via JPA could be easier to work with.

In addition, among the various new RowSet implementations detailed in the article, CachedRowSet's ability to cache data on the client side seems the most interesting feature of this API. The implementation that ships with the JDBC uses sophisticated cache synchronization techniques to ensure that the database's knowledge of data matches the data cached in a rowset instance. Given that CachedRowSet can even serialize its cached results, CachedRowSet seems an ideal candidate for data storage in mobile applications.

However, with many Java enterprise frameworks moving to an O/R mapping approach to data management, what's the future for CachedRowSet and WebRowSet? Have you used any of these APIs in your apps? If so, what is your experience with them?

Topic: Making the Most of JDBC with WebRowSet Previous Topic   Next Topic Topic: Getting Started with EasyMock2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use