When using inferred columns (props.put("columnTypes", ""); ), CsvDriver.writeToCsv gets a NullPointerException.
java.lang.NullPointerException
at org.relique.jdbc.csv.CsvReader.inferColumnTypes(CsvReader.java:269)
at org.relique.jdbc.csv.CsvReader.getColumnTypes(CsvReader.java:262)
at org.relique.jdbc.csv.CsvResultSet.getMetaData(CsvResultSet.java:1234)
at org.relique.jdbc.csv.CsvDriver.writeToCsv(CsvDriver.java:297)
It appears to be caused because resultSet.next() is not called (which sets fieldValues) prior to obtaining the result set metadata to get the column names for the header line. If I call resultSet.next() before setting the header line and use a do{....} while(resultSet.next()) to process each row. It all works fine.
Thank you,
Peter
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will reorganise the method CsvDriver.writeToCsv to avoid this problem.
The NullPointerException will still occur if you set columnTypes to an empty string and call ResultSet.getMetaData() before fetching the first row with ResultSet.next(). In this situation, I will change CsvJdbc to throw an SQLException, as CsvJdbc cannot know the column types at this time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When using inferred columns (props.put("columnTypes", ""); ), CsvDriver.writeToCsv gets a NullPointerException.
java.lang.NullPointerException
at org.relique.jdbc.csv.CsvReader.inferColumnTypes(CsvReader.java:269)
at org.relique.jdbc.csv.CsvReader.getColumnTypes(CsvReader.java:262)
at org.relique.jdbc.csv.CsvResultSet.getMetaData(CsvResultSet.java:1234)
at org.relique.jdbc.csv.CsvDriver.writeToCsv(CsvDriver.java:297)
It appears to be caused because resultSet.next() is not called (which sets fieldValues) prior to obtaining the result set metadata to get the column names for the header line. If I call resultSet.next() before setting the header line and use a do{....} while(resultSet.next()) to process each row. It all works fine.
Thank you,
Peter
I will reorganise the method CsvDriver.writeToCsv to avoid this problem.
The NullPointerException will still occur if you set columnTypes to an empty string and call ResultSet.getMetaData() before fetching the first row with ResultSet.next(). In this situation, I will change CsvJdbc to throw an SQLException, as CsvJdbc cannot know the column types at this time.
Good point, I hadn't thought the second point through. I'll keep that in mind.
Thanks,
Peter
Logged as CsvJdbc bug #86