Currently, I am trying to add my datetime into SQL from JavaFX GUI, but I keep getting the number format exception error. The Datetime format is yyyy-MM-dd HH:mm:ss
, but I can also add in just like 12:30 etc.
private void doAdd() {
//Input from the user in GUI format
int EntryID = Integer.valueOf(tfEntryID.getText());
String PersonName = tfPersonName.getText();
int CheckInTime = Integer.parseInt(tfCheckInTime.getText());
String CheckTime = String.valueOf(CheckInTime);
Date date = new Date(CheckInTime);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
String currentDateTime = format.format(date);
String insertSql = String.format("INSERT INTO entry_records(
EntryID, PersonName, CheckTime) VALUES ('%s', '%s', %s)",
EntryID , PersonName ,currentDateTime );
int rowsAdded = DBUtil.execSQL(insertSql);
if (rowsAdded == 1) {
System.out.println("STATUS: ADD Entry Record (ID" + EntryID + ") Successful!");
} else {
System.out.println("Adding failed!");
}
}