MySQL 流式读取_使用MySQL流式传输大型结果集

我正在开发一个使用大型MySQL表的spring应用程序。加载大表时,我得到一个OutOfMemoryException,因为驱动程序试图将整个表加载到应用程序内存中。

我尝试使用

statement.setFetchSize(Integer.MIN_VALUE);

但是然后我打开的每个ResultSet都挂了close(); 在网上查找时,我发现发生这种情况是因为它尝试在关闭ResultSet之前尝试加载所有未读的行,但事实并非如此,因为我这样做是:

ResultSet existingRecords = getTableData(tablename);

try {

while (existingRecords.next()) {

// ...

}

} finally {

existingRecords.close(); // this line is hanging, and there was no exception in the try clause

}

小表(3行)也会发生挂起,如果我不关闭RecordSet(在一种方法中发生),则会connection.close()挂起。

挂起的堆栈跟踪:

SocketInputStream.socketRead0(FileDescriptor,byte [],int,int,int)行:不可用[本机方法]

SocketInputStream.read(byte [],int,int)行:129

ReadAheadInputStream.fill(int)行:113

ReadAheadInputStream。 readFromUnderlyingStreamIfNecessary(byte [],int,int)行:160

ReadAheadInputStream.read(byte [],int,int)行:188

MysqlIO.readFully(InputStream,byte [],int,int)行:2428 MysqlIO.reuseAndReadPacket(Buffer ,int)行:2882

MysqlIO.reuseAndReadPacket(Buffer)行:2871

MysqlIO.checkErrorPacket(int)行:3414

MysqlIO.checkErrorPacket()行:910

MysqlIO.nextRow(Field [],int,boolean,int,boolean,boolean,布尔值,缓冲区)行:1405

RowDataDynamic.nextRecord()行:413

RowDataDynamic.next()行:392 RowDataDynamic.close()行:170

JDBC4ResultSet(ResultSetImpl).realClose(boolean)行:7473 JDBC4ResultSet(ResultSetImpl).close()行:881 DelegatingResultSet.close ()行:152

DelegatingResultSet.close()行:152

DelegatingPreparedStatement(DelegatingStatement).close()行:163

(这是我的课程)Database.close()行:84

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值