• 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 retrieve 1 million records in DB2 and write to a file?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to use Java to retrieve one million records in DB2 and write the records into a txt file. I think the ResultSet is unable to hold so many records in memory. We also need to get the better performance. How could I do? Hope to get your help. Thanks a lot.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How's about processing the records one at a time, or a block of a couple hundred at a time? A scrollable ResultSet makes paging easy.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dennis Lee:
I have to use Java to retrieve one million records in DB2 and write the records into a txt file. I think the ResultSet is unable to hold so many records in memory. We also need to get the better performance. How could I do? Hope to get your help. Thanks a lot.


Not a problem. Your resultset doesn't really hold the million records in memory ( unless you use a scrollable ResultSet == BAD ). I punch through a million records the same way I punch through 10:

The actual number of records held in memory at one time is equal to the FetchSize of the Statement/ResultSet. For processing a large number of records, you may want to increase the fetch size ( reduces the number of DB calls ) until you find that it's not increasing the application speed anymore.
Jamie
Joe, not sure what this had to do with paging?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jamie Robertson:

Joe, not sure what this had to do with paging?


What do you call it when you work with a block of records rather than an entire result set? And I did not know scrollable ResultSet loads all the results from a query. . .
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Ess:
... And I did not know scrollable ResultSet loads all the results from a query. . .


scrollable results aren't all loaded into memory at first, but as you scroll forwards, the previously fetched results are stored in memory ( to allow you to scroll back ).
When I think of paging resultsets I usually think of web apps displaying parts of large results on a page with a next and back button. I can see what you intended in your post though.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic