可能重复: 如何检查结果集是否有一行或更多?
当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)会返回什么?
发布评论