如何关闭此代码中的 ResultSet、Statement 和 Connection,因为单击几下后,程序给我错误 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:数据源拒绝建立连接,来自服务器的消息:“连接太多"
这是代码...
private void pautoInc() {
int i;
int len;
String code = "";
try {
Statement s = Db.connectDb().createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) AS x FROM product");
while (rs.next()) {
String st = rs.getString("x");
len = st.length();
i = Integer.parseInt(st);
if (len == 1 & i != 9) {
i += 1;
code = "P0000" + i;
} else if (i == 9) {
i += 1;
code = "P000" + i;
} else if (len == 2) {
i += 1;
code = "P000" + i;
} else if (len == 3) {
i += 1;
code = "P00" + i;
}
prodid.setText(code);
}
} catch (Exception e) {
e.printStackTrace();;
}
}
}