Menu

#115 required column names

v1.0 (example)
wont-fix
None
5
2023-11-10
2023-04-05
ohotNik
No

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;

Discussion

  • Scott Conway

    Scott Conway - 2023-07-10

    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?

     
  • Andrew Rucker Jones

    • status: open --> wont-fix
    • assigned_to: Scott Conway
     
  • Andrew Rucker Jones

    Closed for lack of activity.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.