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 Kazuaki Miyauchi <mi...@gmail.com> on 2014/09/24 10:52:20 UTC

Easy get method of record number

 Hi, it seems there is no way to get the numbers of records without
issuing count sql . It is convenient to get the number as following.

<sql:query var="rsSelect" dataSource="${example}" sql="select
firstName, address from member where id = 'aiueo';" />
 <c:if test="${rsSelect.countNum == 0}" >
...

Why is there no function to get record number?

Regards,

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@tomcat.apache.org
For additional commands, e-mail: taglibs-user-help@tomcat.apache.org


Re: Easy get method of record number

Posted by Kazuaki Miyauchi <mi...@gmail.com>.
2014-09-24 22:46 GMT+09:00 Stuart Thiel <st...@gmail.com>:
> However, taglibs aside, I understand your concern. The main reason is
> that the ResultSet can start getting processed immediately under some
> conditions, thus it makes sense not to know the final number of
> records because the database might not have counted the final number
> of records.

 Thanks for your immediate reply, but,
 Using Apache Commons DbUtils, there is length function which show the
final number of records as following.

Object[] pi = (Object[])qr.query(
 for (int i=0; i<pi.length; i++){

 So, the database might return the number of records at first, I suppose.

 Regards.

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@tomcat.apache.org
For additional commands, e-mail: taglibs-user-help@tomcat.apache.org


Re: Easy get method of record number

Posted by Stuart Thiel <st...@gmail.com>.
Hi Kazuaki,

Firstly, be real careful about using SQL taglibs. It very much goes
against the patterns discussed in class for the reasons discussed in
class.

However, taglibs aside, I understand your concern. The main reason is
that the ResultSet can start getting processed immediately under some
conditions, thus it makes sense not to know the final number of
records because the database might not have counted the final number
of records. A corollary from that is that UI often only displays a
certain number of records and only wants a few at a time, so we can
often go a step further and use the LIMIT qualifier (available in many
sql implementations for that purpose).

The good news about the "SELECT COUNT(id)" syntax is that you don't
need ordering, and you're usually selecting on an index, even if not
the primary one, so it can do those counts pretty darn fast. The count
may also prime the next initial select query, on a good db.

On Wed, Sep 24, 2014 at 4:52 AM, Kazuaki Miyauchi <mi...@gmail.com> wrote:
>  Hi, it seems there is no way to get the numbers of records without
> issuing count sql . It is convenient to get the number as following.
>
> <sql:query var="rsSelect" dataSource="${example}" sql="select
> firstName, address from member where id = 'aiueo';" />
>  <c:if test="${rsSelect.countNum == 0}" >
> ...
>
> Why is there no function to get record number?
>
> Regards,
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: taglibs-user-help@tomcat.apache.org
>



-- 
Stuart Thiel, P. Eng.

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@tomcat.apache.org
For additional commands, e-mail: taglibs-user-help@tomcat.apache.org