I am developing a spring application that uses large MySQL tables. When loading large tables, I get an OutOfMemoryException , as the driver tries to load the entire table into the application memory.
I tried to use
statement.setFetchSize(Integer.MIN_VALUE);
but then every ResultSet that I open hangs on close() ; I found this to happen because it tries to load any unread lines before closing the ResultSet, but this is not the case as I do it:
ResultSet existingRecords = getTableData(tablename); try { while (existingRecords.next()) { // ... } } finally { existingRecords.close(); // this line is hanging, and there was no exception in the try clause }
Things happen for small tables (3 rows), and if I don't close the RecordSet (which happened in one method), then connection.close() freezes.
Stack trace:
SocketInputStream.socketRead0 (FileDescriptor, byte [], int, int, int) string: not available [native method]
SocketInputStream.read (byte [], int, int): 129
ReadAheadInputStream.fill (int): 113
ReadAheadInputStream.readFromUnderlyingStreamIfNecessary (byte [], int, int): 160
ReadAheadInputStream.read (byte [], int, int) string: 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, boolean, Buffer): 1405
RowDataDynamic.nextRecord () String: 413
String RowDataDynamic.next (): 392 String RowDataDynamic.close (): 170
JDBC4ResultSet (ResultSetImpl) .realClose (logical) string: 7473 JDBC4ResultSet (ResultSetImpl) .close (): 881 DelegatingResultSet.close (): 152
DelegatingResultSet.close (): 152
DelegatingPreparedStatement (DelegatingStatement) .close (): 163
(This is my class). Database.close (): 84
java spring mysql streaming
configurator Mar 15 '10 at 13:16 2010-03-15 13:16
source share