0

Whenever I try to enter the date into the database using my JavaFX JFXDatePicker in the application. However, it always enters the date as '1992'. I don't even have 1992 available in the choices.

enter image description here enter image description here

When I print the DatePicker.getValue() the correct date is being printed to the console. This is the code:

public void RemRoom() {
    Connection con = null;
    PreparedStatement pst = null;
    ResultSet rs = null;
    try {
        con = DriverManager.getConnection("jdbc:sqlite:Rooms.db");
        pst = con.prepareStatement("UPDATE " + tp + " set isAvail = 'false' where RoomID = '" + rm + "'");
        pst.execute();
        LocalDate sd = ControllerScr2.getInstance().chkIn.getValue();
        System.out.println(sd); 
        pst = con.prepareStatement("UPDATE " + tp + " set StartDate = " + sd + " where RoomID = '" + rm + "'");
        pst.execute();
        pst.close();
        con.close();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
1
  • 1
    The fields you use to store dates are REAL. This means you do not have to give them a date directly, but first convert it to the correct format. For this purpose, SQLite offers the julianday function that accepts as a string argument containing the date and returns a value of type REAL Commented Nov 14, 2017 at 13:07

1 Answer 1

2

Have you tried formatting the date picked?

myDatePicker.getValue().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))

There's also some useful info on how to manipulate DatePickers here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.