如何检查结果集是否有返回的记录而没有在Java中移动光标 [英] How to check if resultset has records returned w/o moving the cursor in Java

查看:70
本文介绍了如何检查结果集是否有返回的记录而没有在Java中移动光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何检查结果集是否返回了一些记录,就像下面一样,

I am wondering how to check if the resultset has some records returned, just like below,

while(((ResultSet) rs).next()){
    ((ResultSet) rs).previous();
    return true;
}

但是由于结果集类型为TYPE_FORWARD_ONLY,所以我无法执行此操作,我的情况下是否有任何可用的便捷API? wasNull肯定不是正确的,谢谢您的指点!

But I can't do this since the result set type is TYPE_FORWARD_ONLY, is there any handy API available for my case? wasNull is not the right one for certain, thank you for any pointers!

甚至

推荐答案

 if(!resultSet.isBeforeFirst()){
   System.out.println("resultset contin no rows");
 }

如果光标在第一行之前,则

isBeforeFirst()返回true;否则,返回true.如果光标在任何其他位置或结果集不包含任何行,则为false

isBeforeFirst() returns true if the cursor is before the first row; false if the cursor is at any other position or the result set contains no rows

这篇关于如何检查结果集是否有返回的记录而没有在Java中移动光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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