Java SQL ResultSet Print print(ResultSet resultSet)

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

Description

print

License

Apache License

Declaration

public static void print(ResultSet resultSet) 

Method Source Code


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

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

public class Main {
    public static void print(ResultSet resultSet) {
        /* Method based on http://stackoverflow.com/a/28165814/3626537 */
        try {/*from w w w.j  a v a2  s.  c  om*/
            ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
            int columnsNumber = resultSetMetaData.getColumnCount();
            while (resultSet.next()) {
                for (int i = 1; i <= columnsNumber; i++) {
                    if (i > 1)
                        System.out.print(",  ");
                    String columnValue = resultSet.getString(i);
                    System.out.print(resultSetMetaData.getColumnName(i) + ": " + columnValue);
                }
                System.out.println("");
            }
        } catch (SQLException exc) {
            exc.printStackTrace();
        }
    }
}

Related

  1. prettyFormat(ResultSet res)
  2. print(ResultSet rs, PrintStream out)
  3. print(ResultSet rs, PrintStream out)
  4. printCols(final ResultSetMetaData paymentTableResultSetMetaData, final String logging_prefix)
  5. printColTypes(ResultSetMetaData rsmd)