With some code, throw a SELECT query, There was a place where the acquisition result was stored in the ** ResultSet type variable rset **.
I wanted to check the number of elements in rset for reading the code, so I added the following code in the middle and executed it.
example.java
int testIndex = 0;
while(rset.next()){
System.out.println("I want to check the number of elements in rset");
System.out.println(++testIndex);
}
Then (although it was completed normally until then) In the process after that, the following exception occurred.
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
When I thought it was strange, I found that next () was wrongly understood. There is also a function to move the cursor from the current position to the next line.
In the above code, I exited the loop with the cursor on the last element, so In the subsequent rset, there is no element to which the cursor is next, The above exception has occurred.
At the same time I want to be careful about next () of ResultSet I learned that the code I added for reading comprehension can be bad.
Resultset's next () is not a "method to determine if there is a ResultSet next".
Recommended Posts