Another chapter in the “tiny CSV library keeps on growing” saga… opencsv 1.5 has gone out the door. The new version includes changes to CSVWriter to allow for easily exporting a SQL table or query to a CVS file.
The new method writeAll(ResultSet rs, boolean includeHeaders) makes exporting SQL to CSV a snap! Does the hard work of coercing Bits, CLOBs, Timestamps and whatnot to Strings on the way out.
Thanks to Sean Sullivan for the good work in adding this feature.
I really like opencsv. It’s small and solves only one problem but does so very well. Perfect!
I find support for ResultSets in OpenCSV a bit irritating. What about a generic ResultSetToStringConverter?
Thanks for your feedback Timo. I initially felt *exactly* the same way and used almost *exactly* the same words when talking with Sean about integrating his changes it into a subclass of CSVWriter.
In fact CSVWriter itself wasn’t even part of opencsv originally, it was a user-driven inclusion. After kicking things around with Sean, after a while I came to the conclusion that dumping the result of a SQL query out to CSV is probably a hugely popular use case for CSVWriter, and the impact was a single new signature with no dependencies outside the JDK. I actually felt adding one new method to CSVWriter was a smaller impact than bundling additional utility classes or subclasses. I reckon its going to make some users day!
If it really drives you crazy, one option is to drop back to opencsv 1.4 which is identical but for the SQL code. But it sounds like you’re more worried about the vision of the library… and let me assure you that I won’t be going crazy with “kitchen sink” inclusions in future versions – tiny and light is the definitely the vision. Thanks so much for your feedback and support, though. I do appreciate it.