The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Fetching number of rows.

Posted by Avery Ford on October 17, 2000 at 11:48 AM

JDBC 2.0 provides to methods to help with this. They are ResultSetObject.last() and ResultSetObject.getRow().

By going to the end of the result set and getting the row you will know how many records are in the resultset.

for example:

ResultSet resultSet = statement.executeQuery(sql);
int numOfRows = 0;

if (resultSet.last) { //if false, no rows in resultset
numOfRows = resultSet.getRow();

In previous version of JDBC u have to do it the old fashion way i guess and count them yourself by iterating through the resultset and incrementing a count.

> How do i fetch the no of rows from a resultset?


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us