• 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

Writing Resultset to File - best way?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Need a high-level opinion.
In writing a resultset to file (through JDBC connection), is it more efficient to write straight to file while looping through the resultset? Or better to put the resultset into a util collection (such as an ArrayList) and then close the JDBC connection before writing the collection to file?
Pros and cons, anyone?
Thanks.
--
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am not an expert, but this is what I learnt in the past 2 weeks, which I think might help you a little bit.
When you get the resultSet from a database, there is a default FetchSize. Everytime you do ResultSet.next(), it will first check whether there are records already fetched. If not, it will connect to the database again and fetch some records(FetchSize amount) and then let you go through them until there is no more records left. So it will be a big problem if your resultset is huge.
My suggestion is use CachedRowSet instead. It will save the entire ResultSet in the cache, and then the database connection closed. Then you can use CachedRowSet.next() and other methods to retrive it and do whatever to it, just like what you would do with the ResultSet. This one should be very fast. However, there is also problem with this one. If your ResultSet is really huge, you may get OutOfMemory Error. If that is the case, you may want to look at the JDBCRowSet or WebRowSet. You can check all three of them out at the java.sun.com tutorials. Here is the link:
http://developer.java.sun.com/developer/Books/JDBCTutorial/chapter5.html
Again, these are what I learnt in past 2 weeks. I am trying it, and ran into some problems. I posted my program and some running results too. The topic is "Please help me with CachedRowSet preformance!" If you interested, you can check it out. Hope someone will help me with it, and maybe it will solve your problem at the mean time.
Sally
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic