I have a CSV file I'm trying to import via jOOQ's loadCSV method. I'd like to import straight into a MySQL database with a DATE column, but my CSV file has dates formatted as YYYYMMDD instead of YYYY-MM-DD. Is there any way I can pass a custom date format (or date parser) to jOOQ for the import process?

Thanks!

有帮助吗?

解决方案

As of jOOQ 3.3, there is no support for such data type transformations in the loader API. But I have registered issue #3221 to add support for this useful feature. I suspect that something like this should be feasible (Java 8 syntax):

ctx.loadInto(AUTHOR)
   .loadCSV(csv)
   .fields(AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
   .values(
      row -> AUTHOR.ID.getDataType().convert(row[0]),
      row -> row[1].split(" ")[0],
      row -> row[1].split(" ")[1]
   )
   .execute();

Contributions welcome, of course ;-)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top