Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CachedRowSet out of memory

alex Kretschmer
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello forum,

I have an out of memory-problem with cachedRowSet.

For testing I have tried CachedRowSet on a DB-file with 100-thousands of records and wanted to "page through" it (platform: Windows 7, MySQL Server Version: 5.1.50-community, Driver mysql-connector-java-5.0.4-bin and mysql-connector-java-5.1.8-bin ).

According the Cached Rowset definition there are "chunks" from the database file processsed. This should have the advantage that it is not necessery to load large result sets (I hope I´m right).

In this test: After 4 pages ( 10 records per page) a got an out of memory-Error.

The code segment:

public static void processData2(Connection conn1) {

try {

CachedRowSet crset = new CachedRowSetImpl() {};

crset.setCommand("select * from basicjdbc ");

int i = 0;
while (crset.nextPage()) {
System.out.println("-page " + i + " -------------------");
while ( {
System.out.println(crset.getInt(1) + " " + crset.getString(2)
+ " " + crset.getString(3));

} catch (SQLException e) {

The program stops at crset.nextPage():

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.nio.ByteBuffer.wrap(
at java.nio.ByteBuffer.wrap(
at java.lang.StringCoding$StringEncoder.encode(
at java.lang.StringCoding.encode(
at java.lang.StringCoding.encode(
at java.lang.String.getBytes(
at com.mysql.jdbc.MysqlIO.unpackNativeEncodedColumn(
at com.mysql.jdbc.MysqlIO.unpackBinaryResultSetRow(
at com.mysql.jdbc.MysqlIO.nextRow(
at com.mysql.jdbc.MysqlIO.readSingleRowSet(
at com.mysql.jdbc.MysqlIO.getResultSet(
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(
at com.mysql.jdbc.MysqlIO.readAllResults(
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(
at com.mysql.jdbc.PreparedStatement.executeQuery(
at com.sun.rowset.internal.CachedRowSetReader.readData(
at com.sun.rowset.CachedRowSetImpl.nextPage(
at testCachedRowSet.TestDBprocess.processData2(
at testCachedRowSet.TestDBprocess.main(

This is a very remarkable behavior because it is about processing only some records and some pages....

Does anyone knows the problem and a solution for it?

Or is there a better solution than CachedRowSet (except a where clause)?

Much thanks

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic