Stop and XML the Rowsets: Using WebRowSet to Create XML

In Java 5 and higher, there is a very convenient way to get data out of a database and into an XML document. This new addition to the JDBC family is called WebRowSet. It's an interface in the javax.sql.rowset package , and the core API has an implementation called WebRowSetImpl. With this class, you can easily convert a database query's ResultSet into an XML representation. From a JDBC result set, you can populate a WebRowSet by using the following:

 import com.sun.rowset.WebRowSetImpl; ResultSet rs = statement.executeQuery("select * from MyTable"); WebRowSetImpl data = new WebRowSetImpl(); ...

Get Wicked Cool Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.