Java SQL ResultSet Read getHtmlTable(ResultSet results)

Here you can find the source of getHtmlTable(ResultSet results)

Description

get Html Table

License

Open Source License

Declaration

public static String getHtmlTable(ResultSet results) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class Main {
    public static String getHtmlTable(ResultSet results) throws SQLException {
        StringBuilder htmlTable = new StringBuilder();
        ResultSetMetaData metaData = results.getMetaData();
        int columnCount = metaData.getColumnCount();

        htmlTable.append("<table>");

        // agregar fila de titulos 
        htmlTable.append("<tr>");
        for (int i = 1; i <= columnCount; i++) {
            htmlTable.append("<th>");
            htmlTable.append(metaData.getColumnName(i));
            htmlTable.append("</th>");
        }// ww w.  ja  va  2  s. c om
        htmlTable.append("</tr>");

        // agregar otras filas
        while (results.next()) {
            htmlTable.append("<tr>");
            for (int i = 1; i <= columnCount; i++) {
                htmlTable.append("<td>");
                htmlTable.append(results.getString(i));
                htmlTable.append("</td>");
            }
            htmlTable.append("</tr>");
        }

        htmlTable.append("</table>");
        return htmlTable.toString();
    }
}

Related

  1. getGeneratedIdFromResultSet(ResultSet resultSet)
  2. getHashMap(ResultSet resultSet)
  3. getHeaders(ResultSetMetaData rsmd)
  4. getHighPrecisionString(ResultSet rs, int ix, int sql_type)
  5. getHtmlRows(ResultSet results)
  6. getId(ResultSet key)
  7. getIndex(ResultSet rs, int index)
  8. getList(ResultSet resultSet, String columnLabel, Class clazz)
  9. getList(ResultSet rs)