com.microsoft.sqlserver.jdbc.SQLServerException: 系统内存不足。请对大型 ResultSet 使用服务器端游标

电脑配置信息:





今天早晨在一个服务器上导数据的时候出现了下面的问题,提示内存不足。

Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.alpha.test.DataBaseManagerTest.testDatabase(DataBaseManagerTest.java:172)
at com.alpha.test.DataBaseManagerTest.main(DataBaseManagerTest.java:30)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 系统内存不足。请对大型 ResultSet 使用服务器端游标: Java heap space。ResultSet 大小:-1,564,181,511。JVM 总内存大小:259,522,560。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.DBComms.receive(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.sendCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteQuery(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)

解决方法:

hibernate.cfg.xml配置文件中connection.url后面添加selectMethod=cursor。

如果利用jdbc连接数据库也是在在url上加上这句话。

例如:

<property name="connection.url">

jdbc:sqlserver://192.168.0.118:1433;databaseName=Test;selectMethod=cursor

</property>


作用:利用服务器端的游标加快速度 
使用:1.执行多个Statements的操作时候用
         2.需要手动使用事务的时候使用

        3.使用SqlServer数据库连接url的时候使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值