Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import java.sql.SQLException; import java.sql.ResultSet; import java.sql.ResultSetMetaData; public class Main { public static Element appendResultSetToNode(Element root, String rowTag, ResultSet rs) throws SQLException { Document doc = root.getOwnerDocument(); ResultSetMetaData meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); int rowCount = 0; while (rs.next()) { Element rowElement = doc.createElement(rowTag); rowElement.setAttribute("row", "" + rowCount); for (int i = 1; i <= columnCount; i++) { rowElement.setAttribute(meta.getColumnName(i), rs.getString(i)); } rowCount++; root.appendChild(rowElement); } return root; } }