• 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

Urgent Java interview question 6+ yrs exp.

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to get 50000 records and want to write in txt file one by one using some specified format, what will the best approach using JDBC.

Java guys give solution !!
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think by using prepared statement
 
Mohan Karthick
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no I want to fetch record one by one say first 100(write in a file) then again another 100 (write in a file). but how to achieve this ?
 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Java guys give solution !!



Ofcause! at your service!

Did you consider to ask this in another forum? anyways.. do you know how to
a) get 50000 records from a DB using JDBC. If not, im sure you can find the
answer in one of your Java books or in an online tutorial.

b) write to a text file? if not, again - try to consult a book or
java.sun.com

/Svend Rost
 
Ranch Hand
Posts: 538
Hibernate Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all !

This is not at all the right forum.
Anyway it should be SQL feature "Fetch Size" through JDBC's "ResultSet.setFetchSize(rows)".

Please consult "Best practices to improve performance in JDBC" at : http://www.precisejava.com/javaperf/j2ee/JDBC.htm#JDBC119

Optimization with ResultSet
...........................
1. Do batch retrieval using ResultSet
ResultSet interface also provides batch retrieval facility like Statement as mentioned above. It overrides the Statement behaviour.
Initially find the default size by using
ResultSet.getFetchSize(); and then set the size as per requirement
ResultSet.setFetchSize(50);
This feature significantly improves performance when you are dealing with retrieval of large number of rows like search functionality.

Best regards.
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use MultiThreading and launch multiple threads doing reading from db and writing to a file simultaneously. Make sure u index the records properly.and You can also use Batch statements in JDBC to gain higher performance.
 
Mohan Karthick
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks friends.

So If I use setFetchSize(50000); then its means its fetching the DB at once and return everything into resultSet. It will redurce the network calls. or should i use 1000 instead of 50000 because transfering 50000 data at a time is also not good. I think 5000 will be better.

1. Now threading I was thinking of making synchronized instead. because when you say multithreading do u mean to say inside rs.next() {} loop I have to use threading , I want to write data squentially in a file as i get in from database.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic