java mysql count number of rows

Я создал этот код, чтобы я мог рассчитать количество строк в моей таблице. Однако Я не могу вернуть подсчитанное число с сообщением об ошибке «не могу вернуть значение из метода, тип результата которого недействителен». Может ли кто-нибудь показать мне, где находится моя ошибка? Большое спасибо!

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&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) {
  }
5
задан amit 22 January 2012 в 11:19
поделиться