Below is the solution I deployed.
1- Include opencsv.jar in the project
2 -
private boolean criaCsv(String select, long parametro, String nomeArquivoCsv) throws Exception
{
try{
File arquivoCsv = new File( caminho + nomeArquivoCsv );
arquivoCsv.createNewFile();
CSVWriter writer = new CSVWriter(new FileWriter(arquivoCsv), CSVWriter.DEFAULT_SEPARATOR);
Boolean includeHeaders = false;
PreparedStatement ps = getConnection().prepareStatement(select, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ps.setFetchSize(FETCH_BD);
ps.setLong(1, parametro);
ResultSet resultSet = (ResultSet) ps.executeQuery();
writer.writeAll(resultSet, includeHeaders);
writer.flush();
writer.close();
return true;
}
catch(Exception e){
log.error("",e);
return false;
}
}
public Connection getConnection()
{
try
{
if( conn == null || conn.isClosed()){
conn = dataSource.getConnection();
conn.setAutoCommit(false);
}
} catch (SQLException e)
{
log.error("", e);
}
return conn;
}