0

I have an xlsx file that has to be read and the date field needs to be written to MYSQL DateTime column.

The date in the excel file is in the format " 2018-08-06 16:32:58"

But when I read it using PoiItemReader and then convert it in a custom rowmapper, I get the below exception :

java.text.ParseException: Unparseable date: "1533553378000"
    at java.text.DateFormat.parse(DateFormat.java:366)
    at org.springframework.batch.item.excel.RowMapperImpl.mapRow(RowMapperImpl.java:63)

I feel that this is due to PoiItemReader not being able to read the date field correctly. Please note that I have tried converting it into sql date using SDF.

Code: https://github.com/vishwabhat19/TimeWorkedData.git

Should i be using XSSFWorkbook instead ? And if I do how would i push this into a Reader? My project is a spring batch project and it needs a InputReader object.

Thank you in advance.

Vishwa Bhat
  • 77
  • 11
  • Use [DateUtil.isCellDateFormatted](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DateUtil.html#isCellDateFormatted-org.apache.poi.ss.usermodel.Cell-) to test, then fetch as a `Date` object rather than a number – Gagravarr Aug 06 '18 at 18:18
  • This takes in a Cell as the variable, but from PoiItemReader there is no way to get a Cell. – Vishwa Bhat Aug 06 '18 at 18:32
  • Based on [a quick look at the source code of the spring batch code](https://github.com/spring-projects/spring-batch-extensions/blob/master/spring-batch-excel/src/main/java/org/springframework/batch/item/excel/poi/PoiSheet.java#L87), they already do the date stuff for you! What is the format string applied to your broken cell? – Gagravarr Aug 06 '18 at 22:55

0 Answers0