Here you can find the source of dumpTable(Connection conn, String TableName, PrintWriter out)
public static void dumpTable(Connection conn, String TableName, PrintWriter out) throws SQLException
//package com.java2s; //License from project: Apache License import java.io.*; import java.sql.*; public class Main { public static void dumpTable(Connection conn, String TableName, PrintWriter out) throws SQLException { Statement st = conn.createStatement(); String Query = "Select * from " + TableName; ResultSet rs = st.executeQuery(Query); while (rs.next()) { String[] items = getResultSetStrings(rs); for (int i = 0; i < items.length; i++) { String item = items[i]; out.print(item);//from ww w. j a v a 2 s . c om if (i < items.length - 1) out.print(", "); } out.println(); } } public static void dumpTable(Connection conn, String TableName, PrintStream out) throws SQLException { Statement st = conn.createStatement(); String Query = "Select * from " + TableName; ResultSet rs = st.executeQuery(Query); while (rs.next()) { String[] items = getResultSetStrings(rs); for (int i = 0; i < items.length; i++) { String item = items[i]; out.print(item); if (i < items.length - 1) out.print(", "); } out.println(); } } public static String[] getResultSetStrings(ResultSet rs) throws SQLException { int nCols = getNumberColumns(rs); String[] ret = new String[nCols]; for (int i = 0; i < ret.length; i++) { ret[i] = rs.getString(i + 1); } return (ret); } public static int getNumberColumns(ResultSet rs) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int nCols = md.getColumnCount(); return (nCols); } }