Just to amplify what Hans said, the reason that retrieving a row count
isn't problematic in JSTL is that the exposed interface ("Result") is
designed to cache rows.  Effectively, JSTL does "count the rows as you
fetch them," and ${result.rowCount} simply resolves to the internal
counter we keep.  We thus don't rely on an out-of-band size returned from
the JDBC driver.

This holds true when 'maxRows' and 'startRow' are specified, too; the row
count always returns the number of rows in the cached result.

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming this summer from Manning Publications)

On Mon, 6 May 2002, Hans Bergsten wrote:

> Paul DuBois wrote:
> > At 14:57 -0700 5/6/02, Hans Bergsten wrote:
> > 
> >> Paul DuBois wrote:
> >>
> >>> After issuing a SELECT query with <sql:query>, you can access the row
> >>> count with ${rs.rowCount} (where rs is the result set variable).
> >>>
> >>> However, in other APIs such as Perl DBI, the equivalent construct
> >>> is deprecated because some drivers do not return a count reliably;
> >>> the recommended course of action is to count the rows as you fetch
> >>> them.
> >>>
> >>> Is there any such constraint or caution in JSTL?
> >>
> >>
> >> The "rowCount" property of the Result class contains the number of rows
> >> in the Result. In other words, if you have limited the amount of
> >> rows with the "maxRows" attribute, "rowCount" has the same value as
> >> "maxRows" and "isLimitedByMaxRows" is "true".
> >>
> >> It's true that JDBC drivers can not provide the number of rows returned
> >> for a query until you retrieve them, but with <sql:query> all rows (upto
> >> "startRow" + "maxRows") are retrieved and the "rowsCount" value is
> >> therefore an accurate number for the number of rows in the Result.
> >>
> >> I hope that made some kind of sense ;-)
> > 
> > 
> > Well, let's see if I understood you. :-) Assuming that I haven't limited
> > the result set with maxRows, then rowCount should indeed contain the
> > number of rows returned by the query.  Right?
> 
> Right :-)
> 
> Hans


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to