File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Urgent Java interview question 6+ yrs exp.

 
Mohan Karthick
Ranch Hand
Posts: 199
  • 0
  • Mark post as helpful
  • send pies
  • 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 !!
 
rehans oberoi
Ranch Hand
Posts: 174
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think by using prepared statement
 
Mohan Karthick
Ranch Hand
Posts: 199
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?
 
Svend Rost
Ranch Hand
Posts: 904
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Eric Lemaitre
Ranch Hand
Posts: 538
Eclipse IDE Hibernate Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
vishwa venkat
Ranch Hand
Posts: 185
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic