This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Memory issue with Result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Memory issue with Result set" Watch "Memory issue with Result set" New topic
Author

Memory issue with Result set

Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90
Hi,

I have a issue, where we are running a query which returns around 25,000 records or more at a time. Storing that in results set and reading one by one to out put to PDF document is giving out of memory isssue. Can you guys tell me what is the other alternative we can do in order to avoid out of memory problem .

I changed the heap size but still it didnot solve the problem.

Thanks
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

This is most likely not caused by jdbc or ResultSet.

Are you by any chance keeping all the results in memory after you read them from the resultset (in a List or some other container)?

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90
We are actually reading directly from results set and transferring data to text file.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Can you show the piece of code where you loop through the resultset and write to the text file?

Regards, Jan
Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90
Here is the code

statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
statement.setFetchSize(3000);
rset = statement.executeQuery(sqlQuery);

//writing data to a text file saved on the server.

out = new BufferedWriter(new FileWriter(outfilename));
while (rset.next ())
{
count++;

out.write(rset.getString (1) + "\t");

out.write(rset.getString (2) + "\t");
out.write(rset.getString (3) + "\t");
}

out.write(rset.getString (4) + "\t");
if (rset.getString(5) != null)
{
out.write(StringUtil.removeDuplicateWhitespace(rset.getString (5)) + "\t");
}
else
{
out.write(rset.getString (5) + "\t");
}

if (rset.getString(6) != null)
{
out.write(StringUtil.removeDuplicateWhitespace(rset.getString (6)) + "\t");

}
else
{
out.write(rset.getString (6) + "\t");

}

out.write(rset.getString (7) + "\n");

}

rset.close();
statement.close()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Memory issue with Result set
 
Similar Threads
OutOfMemoryError when heap size was set to 1G
Dynamically determining the amount of available memory
ANT Complilation Issue
How to increase the Heap size if my server..?
Having memory problems creating excel file using POI API.