Com. microsoft. sqlserver. jdbc. SQLServerException: The result set does not have the current row, and the result set is exhausted.

Source: Internet
Author: User

Com. microsoft. sqlserver. jdbc. SQLServerException: The result set does not have the current row, and the result set is exhausted.
Refer to blog com. microsoft. sqlserver. jdbc. SQLServerException: The result set does not have the current row.

Java obtains the result set, if (rs! = Null), which is different from while (rs. next ().

  1. Com. microsoft. sqlserver. jdbc. SQLServerException: The result set does not have the current row.
  2. St = conn. createStatement ();
  3. ResultSet rs = st.exe cuteQuery (SQL );
  4. If (rs! = Null) {// rs. next (); Error
  5. System. out. println (rs. getRow ());
  6. System. out. println (rs. getString ("name "));
  7. }
  8. St = conn. createStatement ();
  9. ResultSet rs = st.exe cuteQuery (SQL );
  10. While (rs. next () {// rs. next (); OK
  11. System. out. println (rs. getRow ());
  12. System. out. println (rs. getString ("name "));
  13. }
 

Cause: the rs position of the result set is located at the beginning of the first record, that is, 0. Therefore, when the if clause is used for determination, the current behavior of the result set is null.

This is a problem that the ResultSet points to. After the ResultSet value is set, the pointer defaults to the first element whose index is-1,

That is, before the first element in the ResultSet, the pointer points to a non-existent element by default, so an error occurs. You must call the. next () function to traverse the ResultSet.

Related Article

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.