title: How to get row count using ResultSet in Java?
body: <p>I'm trying to create a simple method that receives a ResultSet as a parameter and returns an int that contains the row count of the ResultSet. Is this a valid way of doing this or not so much?</p>
  <pre><code>int size = 0;
      try {
          while(rs.next()){
              size++;
          }
      }
      catch(Exception ex) {
          System.out.println(&quot;------------------Tablerize.getRowCount-----------------&quot;);
          System.out.println(&quot;Cannot get resultSet row count: &quot; + ex);
          System.out.println(&quot;--------------------------------------------------------&quot;);
      }
  </code></pre>
  <p>I tried this:</p>
  <pre><code>int size = 0;
  try {
      resultSet.last();
      size = resultSet.getRow();
      resultSet.beforeFirst();
  }
  catch(Exception ex) {
      return 0;
  }
  return size;
  </code></pre>
  <p>But I got an error saying</p>
  <pre class="lang-none prettyprint-override"><code>com.microsoft.sqlserver.jdbc.SQLServerException: 
  The requested operation is not supported on forward only result sets.
  </code></pre>