required column names
Brought to you by:
aruckerjones,
sconway
Method
com.opencsv.AbstractCSVWriter#writeAll(java.sql.ResultSet, boolean, boolean, boolean)
@Override
public int writeAll(ResultSet rs, boolean includeColumnNames, boolean trim, boolean applyQuotesToAll) throws SQLException, IOException {
int linesWritten = 0;
if (includeColumnNames) {
writeColumnNames(rs, applyQuotesToAll);
linesWritten++;
}
while (rs.next()) {
writeNext(resultService().getColumnValues(rs, trim), applyQuotesToAll);
linesWritten++;
}
return linesWritten;
}
requires columns in resultSet. But if we use jdbcTemplate for creating ResultSet - first row will be data. not columns.
rs.next will skip this line and it will not appear in csv.
Workaround now - add headers to result set like this way:
SELECT 'a', 'b', 'c'
UNION
SELECT * FROM demo;
I am sorry but I cannot recreate your problem. The only thing I can think of is if you are passing a false in the includeColumnNames which causes it to write out the header.
If that is not the case how are you getting your ResultSet? What database are you using that does not populate the names of the values it selected?
Closed for lack of activity.