I have an application with works with a java.sql.ResultSet
, and it needs to be able to export a user-specified subset of the ResultSet
to XML. I'd like to use javax.sql.rowset.WebRowSet
for this, like:
var resultset = connection.createStatement().executeQuery("SELECT …");
var rowset = javax.sql.rowset.RowSetProvider.newFactory().createWebRowSet();
rowset.populate(resultset);
var writer = new StringWriter();
rowset.writeXml(writer);
return writer.toString();
However, this always serializes the entire ResultSet
(which sometimes contains millions of rows). How can I serialize just a few rows of an open ResultSet
to XML without re-executing the query?