我正在一个使用Spring MVC和Spring Data的项目中工作,我想要向本地查询传递一个日期参数,目前我已经有了以下代码。
这是我的查询方法,它在一个继承自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 "
,?2
等于这个字符串: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
。 - M. Deinum