Java SQL ResultSet Print printResultSet(ResultSet rs)

Here you can find the source of printResultSet(ResultSet rs)

Description

Print a ResultSet to System.out.

License

Open Source License

Declaration

public static void printResultSet(ResultSet rs) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.*;

public class Main {
    /**//  ww w .ja  v a2 s . c  om
     * Print a ResultSet to System.out. This is useful for debugging tests.
     */
    public static void printResultSet(ResultSet rs) throws SQLException {
        ResultSetMetaData rsmd = rs.getMetaData();
        for (int i = 1; i <= rsmd.getColumnCount(); i++) {
            if (i != 1) {
                System.out.print(", ");
            }
            System.out.print(rsmd.getColumnName(i));
        }
        System.out.println();
        while (rs.next()) {
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                if (i != 1) {
                    System.out.print(", ");
                }
                System.out.print(rs.getString(i));
            }
            System.out.println();
        }
    }
}

Related

  1. printRecord(PrintWriter pw, ResultSet rs)
  2. printResult(ResultSet rs)
  3. printResults(final ResultSet results)
  4. printResults(ResultSet rst)
  5. printResultSet(List> rows, List colNames)
  6. printResultSet(ResultSet rs)
  7. printResultSet(ResultSet rs)
  8. printResultSet(ResultSet rs)
  9. printResultSet(ResultSet rs)