空结果集 [英] empty resultset
问题描述
你好,
我是java的新手。我的实际问题是:
我如何测试结果集是否为空?
我测试过:
rs == null
rs.next()
rs.isAfterLast()
rs.last()
但结果是异常java.lang.NullPointerException
Hello,
I''m new in java. my actual problem is :
how can i test if a resultset is empty?
I have tested:
rs == null
rs.next()
rs.isAfterLast()
rs.last()
but the result is the exception java.lang.NullPointerException
推荐答案
您好,
我是java的新手。我的实际问题是:
我如何测试结果集是否为空?
我测试过:
rs == null
rs.next()
rs.isAfterLast()
rs.last()
但结果是异常java.lang.NullPointerException
Hello,
I''m new in java. my actual problem is :
how can i test if a resultset is empty?
I have tested:
rs == null
rs.next()
rs.isAfterLast()
rs.last()
but the result is the exception java.lang.NullPointerException
来自文档
"下一个方法将游标移动到下一行,因为当ResultSet对象中没有更多行时它返回false,它可以在while循环中用于迭代结果集
From the docs
"The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set"
谢谢
但如果我尝试迭代我获得java.lang.NullPointerException。可以测试resutset如果为空或没有抛出异常?
Thanks
but if i try to iterate i obtain the java.lang.NullPointerException. It is possible test the resutset if empty or no without throw the exception?
谢谢
但如果我尝试迭代我获得java.lang.NullPointerException。可以测试resutset如果为空或没有抛出异常?
Thanks
but if i try to iterate i obtain the java.lang.NullPointerException. It is possible test the resutset if empty or no without throw the exception?
让我们看看你的代码。您是否正确初始化结果集? executeQuery永远不会返回null。
Let''s see your code. Are you initializing the resultset properly? executeQuery never returns null.
这篇关于空结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!