Im doing a javafx program, which looks like this right now - I messed it up a bit cause I tried several ways, sorry about that:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
button2.setOnAction(e -> popupwindow.close());
button1.setOnAction(e -> {
String startDateString = startDateField.getText();
String endDateString = endDateField.getText();
Date startdate;
Date enddate;
try {
startdate = sdf.parse(startDateString);
enddate = sdf.parse(endDateString);
System.out.println(startdate);
System.out.println(enddate);
Projects project =new Projects(Integer.parseInt(createdByField.getText()),sdf.parse(endDateString),countProjectIdsInList(),projectNameField.getText(),sdf.parse(startDateString));
repo.saveProjects(project);
projects.add(project);
initProjectView();
popupwindow.close();
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
});
But when I run the program, the following error occures:
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect date value: 'Sat Nov 11 00:00:00 CET 1111' for column `projectplanner`.`project`.`end_date` at row 1
The concept is that I add the value of the dates in yyyy-MM-dd format into a textBox, then I want the program to convert the yyyy-MM-dd String into a Date value and upload it into the MySQL table, but in YYYY-MM-DD format aswell. If I understand it correctly, it means that I the MySQL cant convert the timeformat into the correct format. I use plain simple dates in the MySQL and Java too. But somehow the formatter doesnt even convert and I dont understand why. Can someone help please?