Here you can find the source of printResultsToFile(ResultSet rst, File outFile)
public static int printResultsToFile(ResultSet rst, File outFile) throws SQLException, FileNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; public class Main { public static int printResultsToFile(ResultSet rst, File outFile) throws SQLException, FileNotFoundException { // if(!rst.isBeforeFirst()){ // throw new SQLException("Result set not before first"); // } PrintWriter fileprinter = new PrintWriter(outFile); // Print out your results ResultSetMetaData meta = rst.getMetaData(); int numColumns = meta.getColumnCount(); fileprinter.print(meta.getColumnName(1)); for (int j = 2; j <= meta.getColumnCount(); j++) fileprinter.print(", " + meta.getColumnName(j)); fileprinter.println();/*from ww w. ja v a 2 s . co m*/ int count = 0; while (rst.next()) { fileprinter.print(rst.getObject(1)); for (int j = 2; j <= numColumns; j++) fileprinter.print(", " + rst.getObject(j)); fileprinter.println(); count++; } fileprinter.close(); return count; } }