This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory issue with Result set

 
Arathi Raj
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Arathi Raj
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are actually reading directly from results set and transferring data to text file.
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic