title: java mysql count number of rows
body: <p>I created this code to allow me calculate the number of rows in my table. However, I'm not able to return the counted number with an error saying "cannot return a value from method whose result type is void." Could someone show me where' my error? Thanks alot!</p>
  
  <pre><code>public void num() throws Exception {
    try {
        // This will load the MySQL driver, each DB has its own driver
        Class.forName("com.mysql.jdbc.Driver");
        // Setup the connection with the DB
        connect = DriverManager.getConnection("jdbc:mysql://localhost/testdb?"
        + "user=root&amp;password=");
  
        // Statements allow to issue SQL queries to the database
        statement = connect.createStatement();
        resultSet = statement.executeQuery("select * from testdb.emg");
        int count = 0;
        while (resultSet.next()) {
          count++;
        }  
        return count;
    } catch (Exception e) {
    }
  </code></pre>