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 Partial Result Sets 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 "Partial Result Sets" Watch "Partial Result Sets" New topic

Partial Result Sets

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
I was wondering if its possible to only retrieve a partial result set from a query. If I have a large result but only wish to look at the first 25 OR if I was wishing to check out 26 to 50. Can this be done? I'm using db2 with WebSphere 4.0.

By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Some databases allow you to slice the result set in this way, but there's not a standard syntax. PostgreSQL for example, supports the LIMIT and OFFSET keywords. MySQL also allows this with (I believe) two values on the LIMIT keyword. I'm not sure if DB2 even has this capability; you'd need to look into the docs (or someone here with DB2 knowledge might chime in with info).

[Asking smart questions] [About Bear] [Books by Bear]
Vinod John
Ranch Hand

Joined: Jun 23, 2003
Posts: 162
I think JDBC internally has this feature, I may be wrong, there is some way to set the fetch size in the JDBC which restrict the number of rows retrieved in one fetch by default it is 20 (I think).
Can some on confirm this.
[ April 19, 2004: Message edited by: Vinod John ]
Rudy Dakota
Ranch Hand

Joined: Jul 27, 2002
Posts: 54
Hi Vinod,
You 're both right and wrong. What you describe is how the fetch size is supposed to work. But! If you were a driver builder, you are under no obligation to build your driver like that. The fetch size has no more status than a suggestion to the implementor. There is every freedom not to implement it and still maintain that you build a JDBC driver
For us programmers this simply means we can never trust on a driver to implement the fetch size if we haven't somehow checked. And even then, this works behind the scenes, so you 'd better be very sure the driver doesn't do some sort of pre-fetching as well
Good riding,
I agree. Here's the link:
subject: Partial Result Sets
It's not a secret anymore!