java – 在preparedStatement中使用oracle的to_date

我试图在preparedStatement中使用to_date在oracle数据库中输入日期,但是我收到错误.
代码片段:
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));
dateToString方法返回如下值:2012-01-01 12:00:00
错误:
[Oracle][ODBC][Ora]ORA-01861: literal does not match format string
请指教.
解决方法:
您应该使用正确的TO_DATE格式掩码来匹配您的输入.
在你的情况下最有可能:TO_DATE(?,’YYYY-MM-DD HH24:MI:SS’)