Recently encountered a problem: java. SQL. SQLException: After end of result set. This problem has also been found online, because when you reference multiple result sets, since the previous result set has been closed with the database, you reference it again, of course, the result is Null. I can hear it in a single statement. Let's take a look at this program:
Copy to ClipboardReference content: [www.bkjia.com] // find the id of the selected status
Sql1 = "select stateId from state where stateMessage = '"
+ StateBean. getStateMessage () + "'";
ResultSet rs1 = con.exe cuteQuery (sql1 );
Try {
While (rs1.next ()){
StateId = String. valueOf (rs1.getInt (1 ));
}
} Catch (SQLException e ){
E. printStackTrace ();
}
// Find the id of the selected Administrator
Sql2 = "select adminId from admin where adminRealName = '"
+ AdminBean. getAdminRealName () + "'";
ResultSet rs2 = con.exe cuteQuery (sql2 );
Try {
While (rs2.next ()){
AdminId = String. valueOf (rs1.getInt (1 ));
}
} Catch (SQLException e ){
E. printStackTrace ();
}
I wonder if you have noticed the error of row 18th, adminId = String. valueOf (rs. getInt (1); the result set of rs2 must be referenced, but the result set of rs1 that has been disabled previously is referenced. Therefore, an error such as java. SQL. SQLException: After end of result set is a very small detail, but if you are not careful, it may take a long time. Of course, it is also a good thing to make a mistake once. It is also a matter of accumulated experience and a deeper impression. I hope you will not see such a small problem next time.
Note: The executeQuery () method is encapsulated by me.