在preparedStatement中使用oracle的to_date

时间:2012-04-12 08:31:39

标签: java oracle jdbc prepared-statement

我正在尝试使用prepareStatement中的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

请建议。

1 个答案:

答案 0 :(得分:9)

您应该使用正确的TO_DATE格式掩码来匹配您的输入。

最有可能的情况是:TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')