问题: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,因为它已经关闭,所以就会抛出异常。