【发布时间】:2014-11-19 08:48:09
【问题描述】:
我正在使用 spring 工具套件处理 spring MVC 项目和 spring 数据,我想将日期参数传递给本机查询,到目前为止我有这个。
我在扩展 JpaRepository 的接口中的查询方法
@Query(value =
"SELECT "
+ "a.name, a.lastname
+ "FROM "
+ "person a, "
+ "myTable b "
+ "WHERE "
+ "a.name= ?1' "
+ "AND a.birthday = ?2 ",
nativeQuery = true)
public ArrayList<Object> personInfo(String name, String dateBirthDay);
实现这个接口定义的方法:
public ArrayList<Object> getPersonsList(String name, String dateBirthDay) {
ArrayList<Object> results= null;
results= serviceAutowiredVariable.personInfo(name, dateBirthDay);
return results;
}
这就是我从控制器类中调用它的方式。
personsList= _serviceAutowiredVariable.getPersonsList("Jack", "TO_DATE('01-08-2013', 'DD-MM-YYYY')" );
我想在这一行 "AND a.birthday = ?2 " ?2is 等于这个字符串 TO_DATE('01-08-2013', 'DD-MM-YYYY')
但是当我运行我的代码时出现这个错误
[Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.DataException: could not extract ResultSet; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not extract ResultSet] root cause
java.sql.SQLDataException: ORA-01858: a non-numeric character was found where a numeric was expected
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ORA-01858: a non-numeric character was found where a numeric was expected
【问题讨论】:
-
只需传递一个
Date对象而不是String。
标签: java spring spring-mvc jpa spring-data