If you don't need to know the row count before the query is actually
executed, I'll state the obvious:
........................
while (rs.next()) {
rowCount++;
........................
That way, overhead for SELECT COUNT(*) is eliminated.
If you are not the one performing the query, and you are just receiving
a ResultSet object that you want to introspect, then I don't know of
any API method associated with java.sql.ResultSet or
java.sql.ResultSetMetaData that will directly give you that info.
Mike Drummond
----------
From: chris.pratt
To: SERVLET-INTEREST
Subject: Re: JDBC Question
Date: Thursday, June 10, 1999 8:44PM
Normally in SQL you don't know the number of rows until you collect them.
If you actually need to know before hand, issue the "SELECT COUNT(*) WHERE
..." call, you'll get a result set with one integer result that is the
number of rows that a select with the same where clause will return.
(*Chris*)
----- Original Message -----
From: Java List <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 10, 1999 7:31 PM
Subject: JDBC Question
> I've got a servlet that's succesfully connecting to a SQL database
> (mySQL). I'm able to put data into and get data out of the database with
> no probelms. I'm interesting in getting the numbers of records found in a
> ResultSet object. Anyone know of a method in the java.sql.ResultSet()
> class or the java.sql.Statement() class (or any other class) that will
> return the number of found records in a ResultSet Object.
>
> -Nash
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html