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