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 About ResultSet 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 "About ResultSet" Watch "About ResultSet" New topic

About ResultSet

sinasi susam
Ranch Hand

Joined: Jul 15, 2005
Posts: 67
I searched the net for ResultSet and read some about it.I want to listen to your advices,experiences too.

*How does ResultSet work?

*What is Fetch size?

Does ResultSet get all data from db only at once?

Thank you.
Yilmaz Mete

Joined: Dec 23, 2003
Posts: 28


There exists Statement.setMaxRows() which does the same on the Statement Interface.

You can then use ORDER BY DESC/ASC and get the results you need.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

ResultSet provides an interface that the database driver implements to pass you the results of a query. Fetch size is the number of rows the driver gets in each trip to the database. A ResultSet gets all the data at once if the fetch size is larger than the number of rows. Otherwise, it gets it in chunks.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Yilmaz Mete

Joined: Dec 23, 2003
Posts: 28
see sth here....

About the Fetch Size Attribute

Each ResultSet object has a fetch size attribute. This attribute controls how many rows the driver should retrieve from the server in each server request.

If fetch size is 1, the driver will get one row from the server with each method call.

If the fetch size is 20, the driver will get twenty rows from the server on the first All 20 rows will be kept in the driver network buffer. The subsequent 19 calls will not talk to the server at all. On the 20th the server will be asked for the next 20 rows.

The driver is not required to use the fetch size strictly. The driver should use the fetch size only as a recommendation from the application. However, Mimer JDBC does follow a specified fetch size.

When the ResultSet object is created, it inherits the fetch size from the statement object (Statement, PreparedStatement or CallableStatement) that created the ResultSet. The fetch size attribute for the statement object can be manipulated just like the ResultSet attribute but its sole purpose is to provide a default for ResultSet objects.

If the application does not specify a fetch size at all, Mimer JDBC will use whatever fetch size that fits into a 60Kb buffer. If each row takes up 100 bytes the default fetch size will be 600.


How do I set the fetch size?

There are two ways you can set the fetch size:
Set the fetch size on the statement object, thus affecting all ResultSet objects created by the statement object
Set the fetch size individually on each ResultSet object created.

For example, the code sample below creates a PreparedStatement and sets the default fetch size to 1000 rows. This setting could be suitable for a non-interactive caller. Sometimes an interactive part of the application wants to present the same information to the user one screen at a time. In this case, a result set is created from the PreparedStatement and the fetch size is set to 20.

[ August 10, 2005: Message edited by: Yilmaz Mete ]
I agree. Here's the link:
subject: About ResultSet
It's not a secret anymore!