Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle huge data using Resultset

 
yadagiri Sreepadi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Iam developing an application where in I need to read the data from a Table and I had to populate it in the Excel sheet.
In a single stretch Iam fetching some where around 60,000 records from the table. The ResultSet is holding that much of data and then Iam writing the result set in to a File.

Is it the right way to handle the data or is there any optimal way to do this....

Please advice me....
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

A ResultSet is allowed to be lazy. (I once read that they are all lazy when they can be, but can't confirm that myself.) That is, it can pull some subset of rows from the database into its own memory. When you use next() enough times to get to the end of that chunk, it gets more. That means it doesn't have to hold the entire result in memory at one time, designed just for situations like yours.

If you don't hold it all in memory either you may well come out ok. Sounds like you're writing to a file and not filling a collection with data. Have you tried it on large results and run into trouble? Or are you more concerned about scaling up in the future?

You can defeat this lazy scheme by specifying a bi-directional cursor. Make sure your default cursor is forward reading only.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic