oracle 在preparedStatement中使用oracle的to_date
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10120048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using oracle's to_date in preparedStatement
提问by Nelo Angelo
I am trying to enter a date in oracle database using to_date in preparedStatement but I am getting errors.
我试图在preparedStatement 中使用to_date 在oracle 数据库中输入日期,但出现错误。
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
dateToString 方法返回这样的值:2012-01-01 12:00:00
Error:
错误:
[Oracle][ODBC][Ora]ORA-01861: literal does not match format string
Please advice.
请指教。
回答by Anonymous
You should use a correct TO_DATE
format mask to match your input.
您应该使用正确的TO_DATE
格式掩码来匹配您的输入。
In your case most likely: TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
在你的情况下最有可能: TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')