import java.sql.*; public class HtmlResultSet { private ResultSet rs; public HtmlResultSet(ResultSet rs) { this.rs = rs; } public String toString() { // can be called at most once StringBuffer out = new StringBuffer(); // Start a table to display the result set out.append("\n"); try { ResultSetMetaData rsmd = rs.getMetaData(); int numcols = rsmd.getColumnCount(); // Title the table with the result set's column labels out.append(""); for (int i = 1; i <= numcols; i++) { out.append("\n"); while(rs.next()) { out.append(""); // start a new row for (int i = 1; i <= numcols; i++) { out.append("\n"); } // End the table out.append("
" + rsmd.getColumnLabel(i)); } out.append("
"); // start a new data element Object obj = rs.getObject(i); if (obj != null) out.append(obj.toString()); else out.append(" "); } out.append("
\n"); } catch (SQLException e) { out.append("

ERROR:

" + e.getMessage() + "\n"); } return out.toString(); } }