How to get only the first row from a ResultSet

后端 未结 4 403
南旧
南旧 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:17

    Instead of iterating over the result set, just check if there exists an entry an read it:

    ResultSet r = ...;
    if(r.next()) {
      String s = r.getString(1);
      ...
    }
    

提交回复
热议问题