Here you can find the source of printResultSet(ResultSet rs)
public static String printResultSet(ResultSet rs)
//package com.java2s; //License from project: Open Source License import java.io.PrintStream; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; public class Main { public static void printResultSet(ResultSet rs, PrintStream writer) { String print = printResultSet(rs); writer.append(print);// ww w. j a v a 2 s . com writer.flush(); } public static String printResultSet(ResultSet rs) { StringBuilder sb = new StringBuilder(); try { ResultSetMetaData rsMeta = rs.getMetaData(); int colCount = rsMeta.getColumnCount(); int count = 0; while (rs.next()) { sb.append(count++); sb.append("-------------------------------------------------------\r\n"); for (int i = 1; i <= colCount; i++) { sb.append(rsMeta.getColumnLabel(i) + " : " + "\t\t\t" + rs.getString(i) + "\r\n"); } } sb.append("------------------------------------------------------\r\n"); } catch (SQLException ex) { sb.append("***************************************\r\n"); sb.append("* SQLException in outputResultSet: " + ex.getMessage() + "\r\n"); sb.append("* SQLState : " + ex.getSQLState() + "\r\n"); sb.append("* SQL ERROR CODE " + ex.getErrorCode() + "\r\n"); sb.append("***************************************\r\n"); } return sb.toString(); } }