I am trying to enter a date in oracle database using to_date in preparedStatement but I am getting errors.
Code Fragments:
sql = "select Identifier from metadata where content_cdate >=to_date(?,'dd-mm-yyyy') and content_cdate < to_date(?,'dd-mm-yyyy') and status='published' and content_mdate is null";
ps.setString(1, commonUtil.dateToString(startTime));
the dateToString method returns a value like this: 2012-01-01 12:00:00
Error:
[Oracle][ODBC][Ora]ORA-01861: literal does not match format string
Please advice.
You should use a correct
TO_DATEformat mask to match your input.In your case most likely:
TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')