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 "Carole E. Mah" <ca...@mama.stg.brown.edu> on 2002/04/30 15:02:35 UTC

dbtags: rowCount

Here is what it says in the doc:

"The "rowCount" tag prints out the number of rows retrieved from the
database. It can be used inside a ResultSet tag to provide a running count
of rows retreived, or after the ResultSet tag to display the total number.
See the Tag Reference for examples. Using the tag before the ResultSet
will produce an error."

Is there any way to test rowCount before the ResultSet?

That is, if I have "catTable":

catName  color           furType
----------------------------------
Jasmine  Tortoise Shell  long
Honey    Orange Tabby    short
Corinna  Calico          short
Pearl    Silver Tabby    long

And my SELECT statement is: 

SELECT * FROM catTable WHERE color="Black";

Then, because there does not seem to be a way to test the sql query to see
if it returns zero rows, the table headings will always be printed, even
if no table rows print (assuming for this example that the user chose
"Black" for catColor in the HTML form):

<%
     String myColor = request.getParameter("catColor");
%>


<sql:statement id="stmt1" conn="conn1">

  <sql:query>
    SELECT * FROM catTable WHERE color='<%= myColor %>'
  </sql:query>

  <!-- I want to have a conditional test here
       so that is the query above returns zero rows,
       the following HTML does not get printed.
  -->

  <table>
  <tr>
    <td>catName</td>
    <td>color</td>
    <td>furType</td>
  </tr>

  <!-- need to NOT print the above HTML if zero rows
       in query! --> 

  <sql:execute ignoreErrors="true"/>

  <sql:resultSet id="rset2">
    <tr>
      <td><sql:getColumn colName="catName"/></td>
      <td><sql:getColumn colName="color"/></td> 
      <td><sql:getColumn colName="furType"/></td> 
    </tr>
  </sql:resultSet>

  <!-- same here, don't print if zero rows -->
  </table>
  <!-- how? -->

</sql:statement>

That is, because of the ignoreErrors-"true", if there are zero rows,
nothing gets printed out inside the resultSet block.  However, the
literal table header row always gets printed.

Thanks for any advice.

-Carole

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Carole E. Mah                     carolem@stg.brown.edu
           Senior Programmer/Analyst
   Brown University Scholarly Technology Group
               phn 401-863-2669
               fax 401-863-9313
            http://www.stg.brown.edu/
  personal: http://www.stg.brown.edu/~carolem/



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


Re: dbtags: rowCount

Posted by tony <to...@animaproductions.com>.
On Tue, 2002-04-30 at 15:02, Carole E. Mah wrote:


> Then, because there does not seem to be a way to test the sql query to see
> if it returns zero rows, the table headings will always be printed, even
> if no table rows print (assuming for this example that the user chose
> "Black" for catColor in the HTML form):

If you have access to Macromedia Dreamweaver (MX or Ultradev) there is
an included method that you can get inspiration from. It is the "show if
recordset not empty" server behavior.

Cheers

Tony Grant

-- 
RedHat Linux on Sony Vaio C1XD/S
http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html


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


Re: dbtags: rowCount

Posted by Bjørn Bouet Smith <bb...@smithfamily.dk>.
Hi there,

Why not just do it on the client side?

i.e. put a <div id="tablename"> or layer around your table headers, and then
in your <sql:resultSet>
<%
++counter;
%>

And then below your table:

<%
out.println("var counter="+Integer.toString(counter));
%>

<script>
if(counter==0)
{
    document.all.tablename.style.visiblity='hidden';
}
</script>


Something like that.

I have used that method a lot in other web applications where the
application didn't have any clue as how many rows fetched.


¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
Bjørn Bouet Smith
BSW
Stationsvej 23
DK-3480 Fredensborg
Tel. +45 4846 1313
Mob. +45 2448 5099
http://www.bsw.dk

¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨

----- Original Message -----
From: "Carole E. Mah" <ca...@mama.stg.brown.edu>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Tuesday, April 30, 2002 3:02 PM
Subject: dbtags: rowCount


>
> Here is what it says in the doc:
>
> "The "rowCount" tag prints out the number of rows retrieved from the
> database. It can be used inside a ResultSet tag to provide a running count
> of rows retreived, or after the ResultSet tag to display the total number.
> See the Tag Reference for examples. Using the tag before the ResultSet
> will produce an error."
>
> Is there any way to test rowCount before the ResultSet?
>
> That is, if I have "catTable":
>
> catName  color           furType
> ----------------------------------
> Jasmine  Tortoise Shell  long
> Honey    Orange Tabby    short
> Corinna  Calico          short
> Pearl    Silver Tabby    long
>
> And my SELECT statement is:
>
> SELECT * FROM catTable WHERE color="Black";
>
> Then, because there does not seem to be a way to test the sql query to see
> if it returns zero rows, the table headings will always be printed, even
> if no table rows print (assuming for this example that the user chose
> "Black" for catColor in the HTML form):
>
> <%
>      String myColor = request.getParameter("catColor");
> %>
>
>
> <sql:statement id="stmt1" conn="conn1">
>
>   <sql:query>
>     SELECT * FROM catTable WHERE color='<%= myColor %>'
>   </sql:query>
>
>   <!-- I want to have a conditional test here
>        so that is the query above returns zero rows,
>        the following HTML does not get printed.
>   -->
>
>   <table>
>   <tr>
>     <td>catName</td>
>     <td>color</td>
>     <td>furType</td>
>   </tr>
>
>   <!-- need to NOT print the above HTML if zero rows
>        in query! -->
>
>   <sql:execute ignoreErrors="true"/>
>
>   <sql:resultSet id="rset2">
>     <tr>
>       <td><sql:getColumn colName="catName"/></td>
>       <td><sql:getColumn colName="color"/></td>
>       <td><sql:getColumn colName="furType"/></td>
>     </tr>
>   </sql:resultSet>
>
>   <!-- same here, don't print if zero rows -->
>   </table>
>   <!-- how? -->
>
> </sql:statement>
>
> That is, because of the ignoreErrors-"true", if there are zero rows,
> nothing gets printed out inside the resultSet block.  However, the
> literal table header row always gets printed.
>
> Thanks for any advice.
>
> -Carole
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> Carole E. Mah                     carolem@stg.brown.edu
>            Senior Programmer/Analyst
>    Brown University Scholarly Technology Group
>                phn 401-863-2669
>                fax 401-863-9313
>             http://www.stg.brown.edu/
>   personal: http://www.stg.brown.edu/~carolem/
>
>
>
> --
> 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>