tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ALEXANDROS KOTSIRAS" <ALEXANDRO...@prodigy.net>
Subject Re: Quick JDBC Question
Date Sun, 16 Jul 2000 23:41:22 GMT
JDBC 1.22 does not have a method to determine the number of rows that you
query returned before you loop through
the rows.
You can always first execute SELECT count(*) FrOM blah blah
if(rs.getInt(1) > 0)

   SELECT column name from blah blah...
}
----- Original Message -----
From: Kurt B. Pruenner <leak@gmx.at>
To: <tomcat-user@jakarta.apache.org>
Sent: Sunday, July 16, 2000 7:46 AM
Subject: Re: Quick JDBC Question


> Luis Andrei Cobo wrote:
> > How can I tell if I resultset returns 0 rows?
> >
> > i try this:
> >
> > if(rs.next()) {
> >         while(rs.next()) {
> >                 blah blah
> >         }
> > }
> > else {
> >         blah blah
> >         }
> >
> > yet, when I do that it skips over the first row entirely.
>
> Of course it does; you're calling rs.next() twice in a row... :)
>
> As I'm using an older version of Tomcat in conjunction with a MySQL JDBC
> driver that hardly supports anything, I've gone and used the following:
>
> if (rs.next())
> {
>   do
>   {
>     // blah blah
>   }
>   while (rs.next())
> }
> else
>  // blah blah
>
> As you see, it's almost the same code you used, but with a twist... :)
>
> --
> Kurt Pruenner - Haendelstrasse 17 - 4020 Linz - Austria
> http://www.mp3.com/Leak - http://www.ssw.uni-linz.ac.at
>
> np: Gas - Track 5 (Pop)
>


Mime
View raw message