TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG-DEVEL:287] Number of rows in a result set?





Bob Tanner wrote:
> 
> How do I get the number of rows in a JDBC ResultSet when using MySQL for the
> database?
> 
> I know the C API has a function call mysql_num_row(), but I cannot find the
> equivalent to it in the JDBC calls.
> 
> --
> Bob Tanner <tanner@real-time.com>       | Phone : (612)943-8700
> http://www.mn-linux.org                 | Fax   : (612)943-8500
> Key fingerprint =  6C E9 51 4F D5 3E 4C 66 62 A9 10 E5 35 85 39 D9
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-devel-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-devel-help@mn-linux.org

You don't.

It has been a pet peeve of mine concerning the JDBC API for a number of
years.  If the JDBC driver is 2.0 compliant and supports scrollable
cursors (is not of TYPE_FORWARD_ONLY), then do the following

ResultSet t_resultSet = somePreparedStatement.executeQuery();
t_resultSet.last();                     // move the cursor to the last
row in the result set
int t_numRows = t_resultSet.getRow();   // retrieve current row
t_resultSet.first();                    // move the cursor back to the
first row in the result set

Sucks, don't it?

-- 
Perry Hoekstra
E-Commerce Architect
Talent Software Service
dutchman@mn.uswest.net