java.lang.OutOfMemoryError using MySQL
Posted by: hendrik.ladner
Date: March 24, 2005 05:20AM


my application visualizes data contained in a MySQL database.

To avoid unnecessary database queries if the visualization has to be repainted
a global ResultSet variable exists within my class that holds the actual data.
If a repaint is invoked I go through the ResultSet, paint the data and set the ResultSet cursor back to the beginning. So I need a ResultSet like

Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = st.executeQuery(query);

If the user scrolls or zooms the visualization I have to update the ResultSet because different data has to be displayed.

After some updates of the ResultSet I get a java.lang.OutOfMemoryError. I read in many forums that it is possible to tell the MySQL driver with

Statement st = con.createStatement();

not to store the whole ResultSet at the client side, but this does not work with scrollable ResultSets. So this is no option for me.

My problem is, why does the memory usage of the JVM increases until the memory error occurs?
Code example:

public class MyClass {

private ResultSet rs;

private void repaint() {
if(updateNecessary) {
rs = getDataFromDB(...);
while( {
// draw the data

I inserted debug messages that showed the memory usage of the JVM. Nearly each update of the ResultSet increased the used memory. It looks like the garbage collector is not able or to slow to free the no longer used resources of the ResultSet.

I tried to close the ResultSet before the update, but this resulted in a NullPointerException.

Any ideas?

Many thanks and best regards

Options: ReplyQuote

Written By
java.lang.OutOfMemoryError using MySQL
March 24, 2005 05:20AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.