2013-02-09 90 views
1

當調用MySQL存儲我有一個MySQL存儲過程click here for stored procedure,並呼籲使用Hibernate分頁不工作程序使用Hibernate

的過程

Hibernate代碼:

int ps=5; 

    SQLQuery query=session2.createSQLQuery("CALL AbsentReportproc(:_fromdate,:_todate)"); 
      query.setParameter("_fromdate", fromdate); 
      query.setParameter("_todate", todate); 
      query.setFirstResult(ps*(pno-1)); 
      query.setMaxResults(ps); 
      List<Object[]> empList=query.list(); 

當我執行上面的代碼我顯示與以下錯誤消息:

org.hibernate.exception.SQLGrammarException: could not execute query 
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 5' at line 1 

注意:如果我從代碼中刪除下面的語句,我DISPLA在單個jsp中記錄所有記錄Page

query.setMaxResults(ps);

任何人都可以給我解決方案是什麼問題?

謝謝...

回答

0

這顯然是您使用的jdbc驅動程序錯誤;

還與setFetchSize試試這個,如果這不也是工作,然後,

我會建議不要讓細節出大塊的查詢,如果你想顯示他們都並沒有太大數據,並且您應該將所有數據存儲在一個集合中,而無需將此方法調用query.setMaxResults(ps);

而當你想顯示在頁面的數據,然後得到的情況下,subList您使用List,打破在應用層的數據,然後對你的觀點,在這種情況下jsp顯示。