File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 2500
    
    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: 2500
    
    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