没有结果时executeQuery(String sql)会返回什么? [英] What does executeQuery(String sql) return when there are no results?

查看:125
本文介绍了没有结果时executeQuery(String sql)会返回什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何检查结果集是否有一行或更多?

当SQL查询的结果为零行时, executeQuery(String sql)会返回什么?如果它返回 ResultSet 对象,我们将如何检测到SQL Query没有返回任何内容。

What will executeQuery(String sql) return when the result of the SQL Query is zero rows>? If it returns a ResultSet Object, how will we detect that the SQL Query has returned nothing.

假设SQL查询为 SELECT 语句。

Assume the SQL Query to be a SELECT statement.

推荐答案

您检查了 ResultSet的下一个方法。最初ResultSet的光标指向第一行之前,第一次调用next()返回false意味着ResultSet中没有数据。请参阅如何获取ResultSet的大小?,因为Java中的Resultsets没有直接的size()或length()方法。

Did you check ResultSet's next method . Initially the ResultSet's cursor points to before the first row, the very first call to next() returns false implies there was no data in the ResultSet. See How do I get the size of a ResultSet? , since there is no direct size() or length() method for Resultsets in Java.

这篇关于没有结果时executeQuery(String sql)会返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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