Fog Creek Software
g
Discussion Board




ResultSet to XML?

What's the simplest way to take a ResultSet (instance of java.sql.ResultSet) and generate an XML representation?

anon
Tuesday, May 18, 2004

Assuming you can store all of the data in memory, you can use JDOM ( http://www.jdom.org ) to build your XML file.

VERY Roughly:

ResultSet rs = stmt.executeQuery(qry);
Element res = new Element("resultset");
while(rs.next) {
  Element row = new Element("row");
  for(int i=1; i<=totalColumns; i++) {
    Element cell = new Element("cell");
    cell.setText(rs.getInt(i));
    row.addConent(cell);
  }
  res.addContent(row);
}

Brian
Tuesday, May 18, 2004

*  Recent Topics

*  Fog Creek Home