title: My java program isn't counting database rows correctly
body: <p>I'm making a program and I have to get the number of rows in a MySQL database. My table has 4 rows but for some reason I'm getting the number 1 everytime I run the program. Here is my code:</p>
  
  <pre><code>public static void showItems() throws Exception {
      try{
          Connection con = getConnection();
          Statement search = con.createStatement();
          ResultSet rs = search.executeQuery("SELECT COUNT(id) FROM main;");
          int rows = 0;
          rs.beforeFirst();
          while (rs.next()){
              rows++;
          }
          System.out.println(rows);
  </code></pre>
  
  <p>Can someone help me? What am I doing wrong here?
  I tried many different ways and none returns me the correct value.</p>
  
  <p>Thanks in advance!</p>