Here you can find the source of printResultSet(ResultSet rs)
public final static void printResultSet(ResultSet rs) throws SQLException
//package com.java2s; import java.io.PrintStream; import java.sql.Date; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Types; public class Main { public final static void printResultSet(ResultSet rs) throws SQLException { printResultSet(rs, System.out); }//from w ww.j a v a 2 s. co m public final static void printResultSet(ResultSet rs, PrintStream out) throws SQLException { ResultSetMetaData metadata = rs.getMetaData(); int columnCount = metadata.getColumnCount(); for (int columnIndex = 1; columnIndex <= columnCount; ++columnIndex) { if (columnIndex != 1) { out.print('\t'); } out.print(metadata.getColumnName(columnIndex)); } out.println(); while (rs.next()) { for (int columnIndex = 1; columnIndex <= columnCount; ++columnIndex) { if (columnIndex != 1) { out.print('\t'); } int type = metadata.getColumnType(columnIndex); if (type == Types.VARCHAR || type == Types.CHAR || type == Types.NVARCHAR || type == Types.NCHAR) { out.print(rs.getString(columnIndex)); } else if (type == Types.DATE) { Date date = rs.getDate(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(date.toString()); } } else if (type == Types.BIT) { boolean value = rs.getBoolean(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(Boolean.toString(value)); } } else if (type == Types.BOOLEAN) { boolean value = rs.getBoolean(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(Boolean.toString(value)); } } else if (type == Types.TINYINT) { byte value = rs.getByte(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(Byte.toString(value)); } } else if (type == Types.SMALLINT) { short value = rs.getShort(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(Short.toString(value)); } } else if (type == Types.INTEGER) { int value = rs.getInt(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(Integer.toString(value)); } } else if (type == Types.BIGINT) { long value = rs.getLong(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(Long.toString(value)); } } else if (type == Types.TIMESTAMP) { out.print(String.valueOf(rs.getTimestamp(columnIndex))); } else if (type == Types.DECIMAL) { out.print(String.valueOf(rs.getBigDecimal(columnIndex))); } else if (type == Types.CLOB) { out.print(String.valueOf(rs.getString(columnIndex))); } else if (type == Types.JAVA_OBJECT) { Object objec = rs.getObject(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(String.valueOf(objec)); } } else if (type == Types.LONGVARCHAR) { Object objec = rs.getString(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(String.valueOf(objec)); } } else { Object objec = rs.getObject(columnIndex); if (rs.wasNull()) { out.print("null"); } else { out.print(String.valueOf(objec)); } } } out.println(); } } }