Retrieving Results from Oracle
I'm having an OutOfMemory exception being thrown because the Vector cannot store all the information that I am retrieving.
Here's what is known:
There are 99,000 rows being returned with 8 columns of data being retrieved from the database.
The memory appears to be jumping quite rapidly if I try to retrieve the 99,000 rows of results. Is there any possible way I can minimize the memory usage and still retrieve all the results?
Any suggestions? Here is the code below which does the retrieval of information:
</pre>
public Vector getRowInfo(ResultSetMetaData rsmd, ResultSet rs)
throws SQLException
{
Vector vRow = new Vector();
Vector vRowElements = new Vector();
while(rs.next())
{
vRowElements.clear();
for(int i = 1; i <= rsmd.getColumnCount(); i++)
{
vRowElements.addElement(rs.getString(i));
}
vRow.addElement(vRowElements);
}
return vRow;
}
</pre>
Thanks
Presumably you are not trying this in a browser.
You can increase the java heap size by using the command line option -Xmx, you might want to start with -Xmx128m
Alternatively you could just not do this. If you need to process those rows then write a stored procedure. If you are trying to display it in a gui then force the user to specify criteria that limits the size of the set (and still use a stored proc to verify the size.)
Hi thanks for the reply.
I'm actually trying to avoid increasing the heap size because the program escelates to using almost 80MB of RAM. When the standard computer at an office has about 128MB RAM, using close to 70% of it doesn't make much sense.
And also, unfortunately, this is the data returned AFTER a criteria was set. The individuals using the application will need all the relevant data according to that data, even if it is close to 100,000 records =(
Oh well. I guess I'll have to figure another way around this.
PS - You are correct about displaying this in a GUI. The information is thrown into a JTable however, the OutOfMemory exception is thrown long before any of the user interface comes in.
>The individuals using the application will
>need all the relevant data according to that data
...
>into the JTable
Must be talented users if they can use 100,000 rows.
Perhaps you might do a mock up first and show them how hard it is going to be to scroll through 100K rows you might convince them to tell you what they are really looking for and you can use that as criteria.
And a quick calc: 100 bytes per row X 100k rows = 10 meg. And that is probably low for each row and doesn't count the bytes java uses to wrap it. So if they still want 100k rows you might do some real memory calcs and then tell the head dude that all those users are going to need new machines. Unless of course someone convinces them that they don't really need to see 100k rows.
Whelp, I was wrong about one part, it wasn't 99,000 records but actually 198,000 records. The GUI was barely updating itself with all the data that it had.
But regardless of which, my boss still wanted to try to see if I can optimize it so that the results are stored faster. In either case, it wasn't optimized because the memory usage went through the roof. At least, with the new approach, it's not crashing due to lack of memory error.