問題:java.sql.SQLException: After end of result set
代碼如下:
下面看一下這段程序吧:
1 // 查找選擇的狀態對應的id
2 sql1 = " select stateId from state where stateMessage = '"
3 + stateBean.getStateMessage() + "' ";
4 ResultSet rs1 = con.executeQuery(sql1);
5 try {
6 while (rs1.next()) {
7 stateId = String.valueOf(rs1.getInt(1));
8 }
9 } catch (SQLException e) {
10 e.printStackTrace();
11 }
12 // 查找選擇的管理員對應的id
13 sql2 = " select adminId from admin where adminRealName = '"
14 + adminBean.getAdminRealName() + "' ";
15 ResultSet rs2 = con.executeQuery(sql2);
16 try {
17 while (rs2.next()) {
18 adminId = String.valueOf(rs1.getInt(1));
19 }
20 } catch (SQLException e) {
21 e.printStackTrace();
22 }
問題分析:
在while的條件裏已經用了resulset,然後它就關閉了。但是在後面又調用了resultset,因爲它已經關閉,所以就會拋出異常。