Java SQL ResultSet Print printResultSetRow(ResultSet rs)

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

Description

print Result Set Row

License

Open Source License

Declaration

public static void printResultSetRow(ResultSet rs) 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 void printResultSetRow(ResultSet rs) throws SQLException {
        ResultSetMetaData metaData = rs.getMetaData();
        int numColumns = printResultSetHeader(metaData);

        printResultSetRow(rs, numColumns);
    }//from w ww.ja  va  2 s  .co m

    public static void printResultSetRow(ResultSet rs, int numColumns)
            throws SQLException {
        Object obj = null;
        for (int i = 1; i <= numColumns; i++) {
            obj = rs.getObject(i);
            if (obj != null) {
                System.out.print(rs.getObject(i).toString() + "\t");
            } else {
                System.out.print("\t\t");
            }
        }
        System.out.println("");
    }

    public static int printResultSetHeader(ResultSet rs)
            throws SQLException {
        return printResultSetHeader(rs.getMetaData());
    }

    public static int printResultSetHeader(ResultSetMetaData metaData)
            throws SQLException {
        int numColumns = metaData.getColumnCount();
        for (int i = 1; i <= numColumns; i++)
            System.out.print(metaData.getColumnLabel(i) + "\t");
        System.out.println("");
        return numColumns;
    }
}

Related

  1. printResultSet(ResultSet rs)
  2. printResultSet(ResultSet rs)
  3. printResultSetColumns(ResultSet rs)
  4. printResultSetHeader(ResultSet rs)
  5. printResultSetMetadata(ResultSetMetaData rsmd, Writer out)
  6. printResultsToFile(ResultSet rst, File outFile)
  7. printRow(ResultSet pk)
  8. printRsetTypeAndConcurrencyType(ResultSet rset)
  9. printSet(ResultSet set, int columns)