[英]Performance issues when calling MySQL stored procedure using Hibernate
[英]Pagination is not working when calling MySQL Stored Procedure using Hibernate
我有一個MySQL存儲過程, 請單擊此處以獲取存儲過程,並使用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
注意:如果我從代碼中刪除以下語句,則將所有記錄顯示在單個jsp頁面中
query.setMaxResults(ps);
誰能給我解決方案是什么問題?
謝謝...
顯然,這是您正在使用的jdbc驅動程序錯誤。
另外,請使用setFetchSize
嘗試此setFetchSize
,如果仍然無法執行此操作,
如果您要全部顯示並且沒有太多數據,建議不要從查詢中分出詳細信息,而應該存儲所有數據,而不要調用此方法query.setMaxResults(ps);
進入一個集合。
而且,當您希望在頁面中顯示該數據時,如果使用List
,則可以獲取subList
,以在應用程序級別中斷數據,然后在這種情況下將其顯示在jsp
的視圖上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.