Why is “while (rs.next())” necessary here?

前端 未结 5 1381
夕颜
夕颜 2021-01-07 16:08

I want to select the maximum line number from my database \"Logs\" and store it in a variable m.

Here\'s my code:

ResultSet rs          


        
5条回答
  •  独厮守ぢ
    2021-01-07 16:33

    A ResultSet cursor is initially positioned before the first row, the first call to the method next makes the first row the current row, the second call makes the second row the current row, and so on.

    consider you have something like this.

    ->1->2->3
    ^
    

    your "rs" is initially pointed before 1, when you call rs.next() it advances the arrow to point to 1

      ->1->2->3
        ^
    

    so if you do not call the next() method then you do not get the result.

    Hope this helps

提交回复
热议问题