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

advertisement

AddThis Social Bookmark Button

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

Reading from XML

WebRowSet also provides several readXML() methods to read data from valid XML using java.io.InputStream or java.io.Reader instances. You will find this option helpful if your input data is in the form of valid XML that you need to persist to the underlying database before (optionally) doing some other processing.

Benefits and Liabilities

Having shown off the basic operation of the WebRowSet, let's tally up the advantages and disadvantages of using this approach with your data.

Benefits

  • Standard schema makes it possible to produce and consume XML data from different applications without transformation.
  • Ease of data manipulation -- it provides scrolling, updating, caching, and offline edits.
  • Easy transformation from database to XML and vice versa with relatively less coding. Less code means less errors, which means more robust code.
  • Less database updates may help reduce concurrency issues.

Liabilities

  • Performance and throughput may be adversely affected by additional information such as properties and metadata. This may be a more prominent issue in distributed applications since huge XML files are required to transport over the network for substantially less amount of data.
  • A new JDK version is required since this feature is not available in 1.4 or older versions of JDK.

Applicability

The WebRowSet interface is appropriate in following scenarios:

  1. Application integration with XML messaging, which is one of the top contemporary architectural choices. A Java EE application can use JMS-based integration to communicate with external systems while using JDBC to save its own transactional states. In such a scenario, the WebRowSet API reduces programming complexity as well as the amount of code to write.
  2. Content presentation from persistence data sources is usually achieved by retrieving the result set and traversing it in the component (such as JavaServer Pages) that generates them. An alternative to this approach is to transform the result set to XML before applying XSLT and then generate the presentation content. This choice provides better maintainability since it decouples the formatting of the content from the component that presents them.

Conclusion

Until recently, converting data back and forth between database and XML representations used to be a major task that would take a large chunk of application development and testing resources. Fortunately, the newest version of the JDBC API provides features such as precise navigation through the result set, caching of result sets, writing result sets to XML, etc. Given the importance of RDBMS to the enterprise programmer and with the current and ever-growing popularity of Java and XML applications, the features provided by interfaces like WebRowSet will be very useful. So, it is time to rethink if you are still planning to use conventional data access approaches in your next Java/XML application that uses RDBMS for data persistence; WebRowSet may offer a real improvement.

Resources

Sharad Acharya has more than eight years of experience in the software engineering field in multiple business domains including supply chain, insurance, banking, and mortgage.


Return to ONJava.com.