Write a SQL result set to a comma seperated value (CSV) file

From CodeCodex

Revision as of 22:06, 1 January 2007 by WikiSysop (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)



This code requires the use of the free library OpenCSV.

CSVWriter writer = new CSVWriter(new FileWriter("yourfile.csv"), '\t');

java.sql.ResultSet myResultSet;

//set myResultSet to the results of your query here

writer.writeAll(myResultSet, includeHeaders);