Java tutorial
//package com.java2s; import java.io.IOException; import java.io.Writer; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; public class Main { private static void addChildren(Writer writer, ResultSet rs) throws SQLException, IOException { ResultSetMetaData metaData = rs.getMetaData(); int nbColumns = metaData.getColumnCount(); StringBuffer buffer = new StringBuffer(); while (rs.next()) { buffer.setLength(0); buffer.append("<" + metaData.getTableName(1) + ">"); for (int i = 1; i <= nbColumns; i++) { buffer.append("<" + metaData.getColumnName(i) + ">"); buffer.append(rs.getString(i)); buffer.append("</" + metaData.getColumnName(i) + ">"); } buffer.append("</" + metaData.getTableName(1) + ">"); writer.write(buffer.toString()); } } }