title: Getting the count of rows in a Java resultset
body: <p>Does anyone know a better way of getting the number of rows in a Java resultset returned from a MySQL database? The resultset returned is not going to be the total number of rows read from the database so I don't think I can use SQL's <code>COUNT</code> aggregate function.</p>
  
  <pre><code>public static int getResultSetRowCount(ResultSet resultSet) {
      int size = 0;
      try {
          resultSet.last();
          size = resultSet.getRow();
          resultSet.beforeFirst();
      }
      catch(Exception ex) {
          return 0;
      }
      return size;
  }
  </code></pre>