I have a datetime type column in mysql db and file fetching column using jdbctemplate and type casting it to java.util.Date
throws error.
Here is my code :
I have defined the following SimpleDateFormat
private static final SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
and use it like this
String query = "select start_time as starttime from job_tbl";
List<Map<String, Object>> myList = jdbcTemplate.queryForList(query);
for (Map<String, Object> map: myList) {
String dateTime = dateformat.format((java.util.Date) map.get("starttime");
}
The code throws this error:
java.lang.ClassCastException:
java.time.LocalDateTime cannot be cast to java.util.Date
The same functionality was working fine in my old other projects with jdbcTemplate
easily type casted to java.util.Date
but in this new project, it returns date of format java.time.LocalDateTime
, is there any issue with mysql-connector or any other issue??