Java. SQL. SQLException: After end of result set

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.