You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Paul DuBois <pa...@snake.net> on 2002/05/06 23:42:51 UTC

JSTL row count

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?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL row count

Posted by Shawn Bayern <ba...@essentially.net>.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL row count

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
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
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com
JavaServer Pages	http://TheJSPBook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL row count

Posted by Paul DuBois <pa...@snake.net>.
>I would suggest using stored procedures to get exactly the number of row
>you want. Transferring more data than you need in a query takes time as
>mentioned in earlier replies from everyone. Other issues are related to
>connection pooling and scalability. If you're query returns several
>hundred or thousand rows, the query itself is fairly quick in a DB like
>oracle, but you're using the connection for a longer duration. If the
>website is only serving a few concurrent connections you're fine. On the
>otherhand, if you're serving hundreds of connections per second, getting
>800 rows to only show 20 will likely result in timeouts.

That may all be true, but I was asking about the actual way that JSTL
behaves, not about higher level application designn.

>
>I don't know mysql, but another thing to consider.
>
>peter


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL row count

Posted by peter lin <pe...@labs.gte.com>.
I would suggest using stored procedures to get exactly the number of row
you want. Transferring more data than you need in a query takes time as
mentioned in earlier replies from everyone. Other issues are related to
connection pooling and scalability. If you're query returns several
hundred or thousand rows, the query itself is fairly quick in a DB like
oracle, but you're using the connection for a longer duration. If the
website is only serving a few concurrent connections you're fine. On the
otherhand, if you're serving hundreds of connections per second, getting
800 rows to only show 20 will likely result in timeouts.

I don't know mysql, but another thing to consider.

peter


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?
> 
> >
> >Hans
> >--
> >Hans Bergsten          hans@gefionsoftware.com
> >Gefion Software                http://www.gefionsoftware.com
> >JavaServer Pages       http://TheJSPBook.com
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL row count

Posted by Paul DuBois <pa...@snake.net>.
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?

>
>Hans
>--
>Hans Bergsten		hans@gefionsoftware.com
>Gefion Software		http://www.gefionsoftware.com
>JavaServer Pages	http://TheJSPBook.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL row count

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
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 ;-)

Hans
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com
JavaServer Pages	http://TheJSPBook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>