分页代码
/** * 分页 * @Title: paqingBypages * @Description: TODO * @param @param hql * @param @param args * @param @param showpage * @param @param count * @param @return * @throws */ public List paqingBypages(String hql, List args, int showpage, int count) { Session session=GetSession.getsession(); List list=null; Transaction tx=null; try { tx=session.beginTransaction(); Query query=session.createQuery(hql); if(args!=null){ for(int i=0;i<args.size();i++){ query.setParameter(i, args.get(i)); } } int firstResultIndex=(showpage-1)*count; query.setFirstResult(firstResultIndex); query.setMaxResults(count); list=query.list(); tx.commit(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); tx.rollback(); } finally{ session.close(); } return list; } 异常 org.hibernate.exception.GenericJDBCException: 只进结果集不支持请求的操作。 at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:108) at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) at $Proxy6.absolute(Unknown Source) at org.hibernate.loader.Loader.advance(Loader.java:1640) at org.hibernate.loader.Loader.getResultSet(Loader.java:1966) at org.hibernate.loader.Loader.doQuery(Loader.java:829) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) at org.hibernate.loader.Loader.doList(Loader.java:2447) at org.hibernate.loader.Loader.doList(Loader.java:2433) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2263) at org.hibernate.loader.Loader.list(Loader.java:2258) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355) at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1161) at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) at com.qingmou.dao.impl.DaoSupeortImpl.paqingBypages(DaoSupeortImpl.java:245) at com.qingmou.test.Test.main(Test.java:39) Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 只进结果集不支持请求的操作。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.throwNotScrollable(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyResultSetIsScrollable(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.absolute(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104) ... 17 more
我测试以上在hibernate 4.X以上都会报这个问题.
在网上找了几天没找到.有很多人说什么代码错等等的.代码没错.
解决办法
在hibernate.cfg.xml里配置
<property name="jdbc.use_scrollable_resultset">false</property>
或者在
hibernate.properties配置
hibernate.jdbc.use_scrollable_resultset=false
说明:配置结果集是否可滚动.
问题已经解决