Domanda

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!

È stato utile?

Soluzione

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 ;-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top