File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Jobs Discussion and the fly likes Urgent Java interview question 6+ yrs exp. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Careers » Jobs Discussion
Bookmark "Urgent Java interview question 6+ yrs exp." Watch "Urgent Java interview question 6+ yrs exp." New topic
Author

Urgent Java interview question 6+ yrs exp.

Mohan Karthick
Ranch Hand

Joined: Apr 11, 2005
Posts: 199
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 !!
rehans oberoi
Ranch Hand

Joined: Dec 06, 2005
Posts: 174
i think by using prepared statement
Mohan Karthick
Ranch Hand

Joined: Apr 11, 2005
Posts: 199
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 ?
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
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
Eric Lemaitre
Ranch Hand

Joined: Jul 03, 2004
Posts: 538

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.


Eric LEMAITRE
CNAM IT Engineer, MS/CS (RHCE, RHCX, SCJA, SCJP, SCJD, SCWCD, SCBCD, SCEA, Net+)
Free Online Tutorials: http://www.free-tutorials-online.net/
vishwa venkat
Ranch Hand

Joined: Nov 22, 2003
Posts: 185
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

Joined: Apr 11, 2005
Posts: 199
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Urgent Java interview question 6+ yrs exp.