File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes CachedRowSet out of memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "CachedRowSet out of memory" Watch "CachedRowSet out of memory" New topic

CachedRowSet out of memory

alex Kretschmer

Joined: Aug 03, 2012
Posts: 1
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

I agree. Here's the link:
subject: CachedRowSet out of memory
It's not a secret anymore!