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)
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).
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 ]
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, Rudy.