Posts Tagged ‘Just wanted to create a simple loop that will read all’

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

Saturday, July 5th, 2008

Just wanted to create a simple Loop with JDBC/MySQL that will read a big database table and proces the data.

Unfortunately the “Java heap space” error occured.

 The following solution worked though:

stmt = con.createStatement(

ResultSet.TYPE_FORWARD_ONLY,

ResultSet.CONCUR_READ_ONLY);

stmt.setFetchSize(Integer.MIN_VALUE);

 

This will tell the driver to step through the resultset instead of loading everything at once.