aspose file tools*
The moose likes JDBC and the fly likes CachedRowSet out of memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "CachedRowSet out of memory" Watch "CachedRowSet out of memory" New topic
Author

CachedRowSet out of memory

alex Kretschmer
Greenhorn

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 ");
crset.setPageSize(10);
crset.execute(conn1);

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

} catch (SQLException e) {
e.printStackTrace();
}
}


The program stops at crset.nextPage():
Messages

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.nio.ByteBuffer.wrap(ByteBuffer.java:350)
at java.nio.ByteBuffer.wrap(ByteBuffer.java:373)
at java.lang.StringCoding$StringEncoder.encode(StringCoding.java:237)
at java.lang.StringCoding.encode(StringCoding.java:272)
at java.lang.StringCoding.encode(StringCoding.java:284)
at java.lang.String.getBytes(String.java:986)
at com.mysql.jdbc.MysqlIO.unpackNativeEncodedColumn(MysqlIO.java:3480)
at com.mysql.jdbc.MysqlIO.unpackBinaryResultSetRow(MysqlIO.java:3334)
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1326)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2262)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:439)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:1970)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1387)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1195)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:693)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)
at com.sun.rowset.internal.CachedRowSetReader.readData(CachedRowSetReader.java:202)
at com.sun.rowset.CachedRowSetImpl.nextPage(CachedRowSetImpl.java:7394)
at testCachedRowSet.TestDBprocess.processData2(TestDBprocess.java:82)
at testCachedRowSet.TestDBprocess.main(TestDBprocess.java:41)


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


Alex
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CachedRowSet out of memory