我创建了这段代码来计算我的表格中的行数。然而,当我试图返回计数的数字时却出现了一个错误提示:“无法从结果类型为空的方法中返回值”。请问有人能告诉我错在哪里吗?非常感谢!
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) {
}
SELECT COUNT(*) FROM testdb.emg
这样的查询更加高效。 - klaustopher}
,是复制粘贴错误吗? - amit