• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to handle huge data using Resultset

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic