1

我有一个 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);

任何人都可以给我解决方案是什么问题?

谢谢...

4

1 回答 1

0

It is clearly a jdbc driver error that you are using;

Also try this with setFetchSize , and if this doesn't work also then,

I would suggest not to get the details out of the query in chunks if you want to display them all and there is not much data and you should rather store all the data without calling this method query.setMaxResults(ps); into a collection.

And when you want to display that data in pages, then get subList in case you are using List, to break the data at the application level and then display it on your view that is jsp in this case.

于 2013-02-09T06:58:58.427 回答