Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Java SQL cant insert Date and Time

I keep getting this error

class java.time.format.Parsed cannot be cast to class java.time.LocalDate (java.time.format.Parsed and java.time.LocalDate are in module java.base of loader 'bootstrap')

I am trying to insert date and time values into my database.

My code:

String sTime = Helper.readString("Enter Closing Time (HH:MM:SS) > ");
            try {
                Time time = new Time(timeFormat.parse(sTime).getTime());
                String sDate = Helper.readString("Enter Date (YYYY-MM-DD) > ");
                LocalDate date = (LocalDate) dateFormat.parse(sDate);
                String event = Helper.readString("Enter Event > ");

                addStadium(id, name, category, time, date, event);

            } catch (ParseException e) {
            }




private void addStadium(String id, String name, String category, Time time, LocalDate date, String event) {
        try {
            String query = "INSERT INTO Stadium(ID, Name, Category, ClosingTime, DateUnavailable, Event) "
                    + "SELECT J.ID,J.Name, J.Category, J.ClosingTime, U.DateUnavailable, U.Event FROM jogging_spot J INNER JOIN unavailability_date U ON J.ID = U.ID "
                    + "VALUES('" + id + "', '" + name + "', '" + category + "', '" + time + ", " + date + ", '" + event + "')";

            PreparedStatement pstmt = conn.prepareStatement(query);
            pstmt.execute();

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

Answer*

Cancel
1