This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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').