Java SQL ResultSet to resultSetToString(ResultSet resultSet)

Here you can find the source of resultSetToString(ResultSet resultSet)

Description

result Set To String

License

Apache License

Declaration

public static StringBuilder resultSetToString(ResultSet resultSet) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static StringBuilder resultSetToString(ResultSet resultSet) throws SQLException {
        ResultSetMetaData metaData = resultSet.getMetaData();
        int countOfColumns = metaData.getColumnCount();
        StringBuilder builder = new StringBuilder();
        builder.append("<table>");
        builder.append("<tr>");
        for (int i = 0; i < countOfColumns; i++) {
            builder.append("<th>");
            builder.append(metaData.getColumnName(i + 1));
            builder.append("</th>");
        }/*from  w ww.j av a 2s  .c o  m*/
        builder.append("</tr>");

        while (resultSet.next()) {
            builder.append("<tr>");
            for (int i = 0; i < countOfColumns; i++) {
                builder.append("<td>");
                builder.append(resultSet.getString(i + 1));
                builder.append("</td>");
            }
            builder.append("</tr>");
        }
        builder.append("</table>");
        return builder;

    }
}

Related

  1. resultSetToHtmlTable(java.sql.ResultSet rs)
  2. resultSetToMap(Map mappedValues, java.sql.ResultSet rs, int key, int value)
  3. resultSetToMap(Map mappedValues, ResultSet rs)
  4. resultSetToOrderedMap(ResultSet rs)
  5. resultSetToSet(PreparedStatement statement)
  6. resultSetToString(ResultSet resultSet)
  7. resultSetToXML(ResultSet rs)
  8. toArrayList(ResultSet rs)
  9. toAttributeMap(ResultSet resultSet)