如何只从ResultSet获取第一行 [英] How to get only the first row from a ResultSet

查看:1999
本文介绍了如何只从ResultSet获取第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何只从 ResultSet 获取第一行?我知道如何遍历整个集合,但是如何才能获得第一行?

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?

推荐答案

而不是迭代结果集,只检查是否存在条目读取它:

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);
  ...
}

这篇关于如何只从ResultSet获取第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆