I'm populating a file from a resultSet like so :
String entries = new String;
entries = rs.getString(1);
entries = ",";
entries = rs.getString(2);
println("entries : "+entries);
You can use the
Constructor as mentioned by @Matten and along with that, use the other writeAll() of
OpenCSV also provides support to dump data from SQL table directly to CSV. For this we need ResultSet object. Following API can be used to write data to CSV from ResultSet.
java.sql.ResultSet myResultSet = getResultSetFromSomewhere(); writer.writeAll(myResultSet, includeHeaders);
writeAll(ResultSet, boolean) method is utilized for this. The first argument is the
ResultSet which you want to write to CSV file. And the second argument is
boolean which represents whether you want to write header columns (table column names) to the file or not.