I want to print the query table results on a CSV file.
I tried using this code:
PrintWriter csvWriter = new PrintWriter(new File(path + "SqlClient_" + date + ".csv")) ;
ResultSetMetaData meta = rs.getMetaData() ;
int numberOfColumns = meta.getColumnCount() ;
String dataHeaders = "\"" + meta.getColumnName(1) + "\"" ;
for (int i = 2 ; i < numberOfColumns + 1 ; i ++ ) {
dataHeaders += ",\"" + meta.getColumnName(i) + "\"" ;
}
csvWriter.println(dataHeaders) ;
while (rs.next()) {
String row = "\"" + rs.getString(1) + "\"" ;
for (int i = 2 ; i < numberOfColumns + 1 ; i ++ ) {
row += ",\"" + rs.getString(i) + "\"" ;
}
csvWriter.println(row) ;
}
csvWriter.close();
This is what i obtain:
title1","title2","title3"
"date1","date2","date3"
....
This is write inside a single column, instead i want to write on different column, something like:
title1 | title2 | title3
data1| data2 | data3 |
There is a special command to split the string into different columns?
|instead of","?