0

Here is my code :

private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("MM-dd-yyyy");
   if(rs.next())
     {
         event.get(i).setDateofbirth(rs.getDate("DOB_EMP").toLocalDate().format(FORMATTER)); // this line is giving error
     }

Here is the error trace :

com.ibm.db2.jcc.am.SqlException: [jcc][1093][10425][4.19.66] Invalid data conversion: Parameter instance  is invalid for the requested conversion to java.sql.Date. ERRORCODE=-4220, SQLSTATE=null

I tried giving the date in this format :

private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-mm-dd");

But I got this error:

java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: MinuteOfHour
aka_code
  • 84
  • 10
  • The latter error is resolved here: [Convert LocalDate in DD/MM/YYYY LocalDate \[duplicate\]](https://stackoverflow.com/questions/54896499/convert-localdate-in-dd-mm-yyyy-localdate). – Ole V.V. May 21 '20 at 09:40
  • As an aside, instead of `rs.getDate("DOB_EMP").toLocalDate()` I would prefer `rs.getObject("DOB_EMP", LocalDate.class)`. It probably won’t resolve your error, though (you may try). – Ole V.V. May 21 '20 at 09:49
  • I updated the mm to MM , and also used getObject.. but I'm getting error as : com.ibm.db2.jcc.am.SqlSyntaxErrorException: [jcc][t4][1092][13956][4.19.66] Invalid data conversion: Wrong result column type for requested conversion. ERRORCODE=-4461, SQLSTATE=42815 – aka_code May 21 '20 at 09:59
  • What is the datatype in DB2 of the `DOB_EMP` column? – Ole V.V. May 21 '20 at 10:01
  • What should I use in my getter, setter methods ? – aka_code May 21 '20 at 10:03
  • It is TIMESTAMP in DB2 – aka_code May 21 '20 at 10:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/214325/discussion-between-ole-v-v-and-aka-gk). – Ole V.V. May 21 '20 at 10:09
  • can you provide the sample date value from your DB – NKR May 23 '20 at 14:36

0 Answers0