源码:
Query query = session.createQuery(hql);
if(firstindex!=-1&&maxresult!=-1){
query.setFirstResult(firstindex);
query.setMaxResults(maxresult);
}
List<T> temp = query.list();
qr.setResultList(temp);
qr.setTotalrecord(temp.size());
报错:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.util.db.BaokuQuery.getScrollData(BaokuQuery.java:31)
at com.baokubiz.systemset.account.logic.implement.AccountServiceImpl.findByNameAndCid(AccountServiceImpl.java:852)
at com.baokubiz.systemset.account.controllers.AccountOSAction.accountlist_unsort(AccountOSAction.java:1984)
Caused by: java.sql.SQLException: ResultSet may only be accessed in a forward direction.
at net.sourceforge.jtds.jdbc.JtdsResultSet.checkScrollable(JtdsResultSet.java:316)
at net.sourceforge.jtds.jdbc.JtdsResultSet.absolute(JtdsResultSet.java:713)
原因:
query.setFirstResult(firstindex);
query.setMaxResults(maxresult);
在sqlserver中,firstindex\maxresult两个参数不能为负数。
参考资料:http://www.iteye.com/post/153764
修改方案:
Query query = session.createQuery(hql);
if(firstindex>=0&&maxresult>=0){
query.setFirstResult(firstindex);
query.setMaxResults(maxresult);
}
List<T> temp = query.list();
qr.setResultList(temp);
qr.setTotalrecord(temp.size());
分享到:
相关推荐
ResultSet的用法
ResultSet 转为listmap
这是一个关于jdbc的文档。很适合于初学者
java数据库连接ResultSet
ResultSet直接在JTable显示
但它仍不支持逆向映射 (REF CURSOR->ResultSet),因此当前版本的数据库仍然不支持 IN 和 IN OUT 参数。 在本方法指南中,我们拥有两个 Java 存储过程。Java 存储过程 getEmployees() 将 SCOTT 模式中 EMP 表的所有列...
Unknown column 'fillMen' in 'field list' java.sql.SQLException: Operation not ...java.sql.SQLException: QueryRunner requires a DataSource to be invoked in this way, or a Connection should be passed in
这是一个用来教你如何使用ResultSet 获取数据对象的文档,非常使用
JAVA 版本ResultSet 转换为JAVABEAN的工具类
ResultSet.TYPE_FORWARD_ONLY:(缺省类型),ResultSet指针只允许向前移动,并且不会受到其他用户对该数据库所作更改的影响。 TYPE_SCROLL_INSENSITIVE:ResultSet指针可以前后移动,甚至可以进行特定定位,例如移...
获得结果集的字段名称,ResultSet的属性要调用ResultSetMetaData的方法
jsp 三种查询分页 resultset,hibernate ,存储过程jsp 三种查询分页 resultset,hibernate ,存储过程jsp 三种查询分页 resultset,hibernate ,存储过程jsp 三种查询分页 resultset,hibernate ,存储过程
poi根据ResultSet到处Excle源码,包含项目所需jar包,可以直接运行
resultset 变成 XML 格式输出
ResultSet转List
javaResultSet常用方法.pdf
ResultSet转化为json,json转化为List,轻松搞定
ResultSet常用方法,指针滚动,讲解很详细哦!
次类对ResultSet进行封装,可以将其转化为List,Map,BO等
ResultSet转化为Model,将从数据库中取得数据进行转化,方便对数据进行操作。