我正在使用spring工具套件處理Spring MVC項目和spring數據,我想將日期參數傳遞給本機查詢,至此爲止我已經完成。Spring Data JPA如何傳遞日期參數
延伸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'對象而不是'St ring'。 – 2014-09-24 18:41:21