How to get only the first row from a ResultSet

后端 未结 4 390
南旧
南旧 2021-01-01 12:17

How do I get only the first row from a ResultSet? I know how to iterate through the entire set, but how do I get just the first row?

4条回答
  •  暖寄归人
    2021-01-01 13:03

    You can use absolute to navigate to the first row:

    ResultSet rs = ...;
    rs.absolute(1); // Navigate to first row
    int id = rs.getInt("id");
    ...
    

提交回复
热议问题