File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes How to get Data in Batches Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to get Data in Batches" Watch "How to get Data in Batches" New topic

How to get Data in Batches

Sunil K Bansal
Ranch Hand

Joined: Jan 04, 2001
Posts: 62
I am building an application in whcih I want that
when I execute a query the selected rows may be 4000
transfering these rows on the network will take mmore time
I want that the first I will get the say 50 rows
if wanted value is in those 50 rows then i dont need
the rest result so I dont want the rest result should
travel the network so I can close ResultSet
if the required value is not in the first 50 rows
then i should be able to call the next 50 rows
and this process can be repeated
till the end of ResultSet
If this can be done
please help me
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I should defintiely put this in a FAQ!
The ResultSet does not contain any data! If you do a "select * from a" where a is a table with 100,000,000 rows, you do not transfer 100,000,000 rows worth of data to your program! The ResultSet is only a way to transfer data, one row at a time, from the database to your program. When you do a, the ResultSet goes out to the database and gets a single row. So don't worry about transferring 4,000 rows from the database to your ResultSet. If the row you wanted was the 63rd row then only 63 rows will travel across the network.
Now if you'll excuse me I need to go bang my head against a wall.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Mark Leong
Ranch Hand

Joined: Dec 11, 2000
Posts: 60
How to retrieve rows 150 to 200 with going through rows 1 to 149?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
That can't be done. If you can't figure out a solution in SQL then JDBC doesn't have a solution either.
I agree. Here's the link:
subject: How to get Data in Batches
It's not a secret anymore!