does there exist a java function I can call that will return the number of rows returned from a sql select query, so i don't have to "select count(*)"? ...i guess i'm looking for something like the " mysql_num_rows" function in PHP.
Joined: May 17, 2004
You have two options.
1.) Since the ResultSet interface doesn't provide you direct access to the number of rows, you could fairly easily iterate through it to get the count yourself using the first() and next() methods to traverse ResultSet. A static helper method could easily be created to do this, if need be.
2.) Since the implementation of ResultSet depends on your database vendor, you could make assumptions based on your architecture. e.g. My database is Oracle, therefore ResultSet is really an OracleResultSet. You can then look for the convenience method in the implementation class. From a design standpoint, this creates an awkward coupling that you may not wish to create for a variety of reasons. The only real reason for doing this as opposed to #1 might be performance (it's potentially more 'native').