Java SQL ResultSet Print print(ResultSet rs, PrintStream out)

Here you can find the source of print(ResultSet rs, PrintStream out)

Description

Prints data contained in provided ResultSet instance as tab-separated table; first line will contain column names.

License

Open Source License

Parameter

Parameter Description
rs ResultSet instance

Exception

Parameter Description
SQLException an exception

Declaration

public static void print(ResultSet rs, PrintStream out) throws SQLException 

Method Source Code

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

import java.io.PrintStream;
import java.sql.*;

public class Main {
    /**//from  www .jav a  2 s  .c  o m
     * Prints data contained in provided {@link ResultSet} instance as tab-separated table; first line will contain column
     * names. Mainly for debug purposes, quite easy to copy-paste output to spreadsheet application
     *
     * @param rs {@link ResultSet} instance
     * @throws SQLException
     */
    public static void print(ResultSet rs, PrintStream out) throws SQLException {
        final ResultSetMetaData metaData = rs.getMetaData();
        final int count = metaData.getColumnCount();

        for (int i = 1; i <= count; i++) {
            out.print(metaData.getColumnName(i) + "\t");
        }
        out.println();

        while (rs.next()) {
            for (int i = 1; i <= count; i++) {
                out.print(rs.getObject(i) + "\t");
            }
            out.println();
        }
    }
}

Related

  1. prettyFormat(ResultSet res)
  2. print(ResultSet resultSet)
  3. print(ResultSet rs, PrintStream out)
  4. printCols(final ResultSetMetaData paymentTableResultSetMetaData, final String logging_prefix)
  5. printColTypes(ResultSetMetaData rsmd)
  6. printHeader(PrintWriter pw, ResultSet rs)
  7. printHeaders(ResultSetMetaData rsmd, PrintStream out)