Menu

Bug in CsvDriver.writeToCsv with infered columns

2013-08-13
2013-08-14
  • Peter Gallanis

    Peter Gallanis - 2013-08-13

    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

     
  • Simon Chenery

    Simon Chenery - 2013-08-13

    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.

     
  • Peter Gallanis

    Peter Gallanis - 2013-08-13

    Good point, I hadn't thought the second point through. I'll keep that in mind.

    Thanks,
    Peter

     
  • Simon Chenery

    Simon Chenery - 2013-08-14

    Logged as CsvJdbc bug #86

     

Log in to post a comment.