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

From CodeCodex

Implementations[edit]

Java[edit]

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);