Here you can find the source of resultSetToHtmlTable(java.sql.ResultSet rs)
public static String resultSetToHtmlTable(java.sql.ResultSet rs) throws SQLException
//package com.java2s; /*//from w w w . j a v a2 s .c o m * Copyright(c) 2012 Saarland University - Information Systems Group * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.sql.ResultSetMetaData; import java.sql.SQLException; public class Main { public static String resultSetToHtmlTable(java.sql.ResultSet rs) throws SQLException { int rowCount = 0; final StringBuilder result = new StringBuilder(); result.append("<P ALIGN='center'>\n<TABLE BORDER=1>\n"); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); //header result.append("\t<TR>\n"); for (int i = 0; i < columnCount; ++i) { result.append("\t\t<TH>").append(rsmd.getColumnLabel(i + 1)).append("</TH>\n"); } result.append("\t</TR>\n"); //data while (rs.next()) { ++rowCount; result.append("\t<TR>\n"); for (int i = 0; i < columnCount; ++i) { String value = rs.getString(i + 1); if (rs.wasNull()) { value = "<null>"; } result.append("\t\t<TD>").append(value).append("</TD>\n"); } result.append("\t</TR>\n"); } result.append("</TABLE>\n</P>\n"); return result.toString(); } }