SQL query a db table WHERE date value comes from Form
I am attempting to do a SQL query for row/s in a table with a date-only value from a datepicker element
within the form.
The script doing this is a bean shell validator.
So i try to get the value of the datepicker element like this:
Form form = FormUtil.findRootForm(element);
Element fldreservationDate = FormUtil.findElement("reservationDate", form, formData);
String[] strreservationDate = FormUtil.getElementPropertyValues(fldreservationDate, formData);
LogUtil.info("","reservationDate " + Arrays.toString(strreservationDate) );
Log shows
INFO 26 Apr 2021 06:57:33 - jwc_xxxx : reservationDate [27-04-2021]
However when i execute the SQL thus:
PreparedStatement stmt = con.prepareStatement("SELECT c_reservationDate FROM app_fd_hotdesk_reservation WHERE c_reservationDate=?");
stmt.setObject(1, strreservationDate);
ResultSet rs = stmt.executeQuery();
No rows were returned even though I'm sure there is such a row in the table!
Querying SELECT c_reservationDate FROM app_fd_hotdesk_reservation WHERE c_reservationDate='2021-04-27'
successfully returns the row...
LogUtil.info("", (rs.getObject("c_reservationDate") != null)? rs.getObject("c_reservationDate").toString():"");
show this in the log:
3681INFO 26 Apr 2021 06:57:34 - jwc_xxxx : 2021-04-27
I'm quite sure it's a date format issue...The datepicker's data format is already set to yyyy-MM-dd
How best to construct the SQL to achieve what i want?