I am trying to save date and time in the attribute of datetime
type ('0000-00-00 00:00'
). I used the following code. But error - HTTP Status 500 - Internal Error
comes up, because of line 6
displaying the following error message:
java.time.format.DateTimeParseException: Text '2017-04-30 23:59 could not be parsed at index 10
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm");
LocalDateTime forDate = LocalDateTime.parse(newDate, formatter);
out.println(forDate);
ps = con.prepareStatement("INSERT INTO reminder_logs VALUES(NULL, ?, ?)");
ps.setInt(1, r_id);
ps.setDate(2, forDate);
i = ps.executeUpdate();
Edited: Error - HTTP Status 500 - Internal Error
I tried to use setTimestamp(2, forDate)
instead of setDate(2, forDate)
but then I got an error saying - incompatible types : LocalDateTime
cannot be converted to Timestamp
.
I tried to take references from the below links but none of them helped:
What can I do to solve this error? I am running java se 8.