简体   繁体   English

Spring JDBC模板SQL-Query按日期过滤

[英]Spring JDBC Template SQL-Query filtered by date

I need to get filter my query by two dates. 我需要按两个日期过滤我的查询。 This is working when I query for it with the Oracle SQL Developer or right out of Eclipse: 当我使用Oracle SQL Developer或Eclipse之外查询它时,这是有效的:

select * from TABLE where rechnungs_eingang >= '06.08.2012' AND rechnungs_eingang <= '06.08.2015')

But if I try to get the data via my webservice I've implemented with Spring 4 I get this exception: 但是,如果我尝试通过我的Web服务获取数据,我已经使用Spring 4实现了,我得到了这个例外:

Caused by: org.springframework.dao.DataIntegrityViolationException: StatementCallback; SQL [select * from TABLE where rechnungs_eingang >= '06.08.2012' AND rechnungs_eingang <= '05.05.2014')]; ORA-01843: not a valid month
; nested exception is java.sql.SQLException: ORA-01843: not a valid month

What and why is happening here? 这里发生了什么和为什么?

You need to use the to_date function and provide a date format mask if you pass in a string value in the query. 如果在查询中传入字符串值,则需要使用to_date函数并提供日期格式掩码 Like this: to_date('06.08.2012', 'DD.MM.YYYY') . 像这样: to_date('06.08.2012', 'DD.MM.YYYY')

The reason why you got this working in SQLDeveloper without providing a date format is likely that the default format used in your locale is 'DD.MM.YYYY' and the implicit VARCHAR -> DATE conversion happens correctly. 您在SQLDeveloper中使用它而不提供日期格式的原因可能是您的语言环境中使用的默认格式为'DD.MM.YYYY' ,并且隐式VARCHAR - > DATE转换正确发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM