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 ().
- Com. microsoft. sqlserver. jdbc. SQLServerException: The result set does not have the current row.
- St = conn. createStatement ();
- ResultSet rs = st.exe cuteQuery (SQL );
- If (rs! = Null) {// rs. next (); Error
- System. out. println (rs. getRow ());
- System. out. println (rs. getString ("name "));
- }
- St = conn. createStatement ();
- ResultSet rs = st.exe cuteQuery (SQL );
- While (rs. next () {// rs. next (); OK
- System. out. println (rs. getRow ());
- System. out. println (rs. getString ("name "));
- }
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.