Getting row count from executeQuery()
Row count is not returned by executeQuery(). It means that if we want to get row count, we have to count them ourselves. It is shown in the following example:
Code:
Statement s = conn.createStatement ();
s.executeQuery ("SELECT id, name, category FROM animal");
ResultSet rs = s.getResultSet ();
int count = 0;
while (rs.next ())
{
int idVal = rs.getInt ("id");
String name = rs.getString ("name");
System.out.println ("name = " + name);
++count;
}
rs.close ();
s.close ();
System.out.println ("No of rows retrieved: " count);