java中如何获取Resultset的长度或大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19829123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how get length or size of Resultset in java
提问by java baba
I want to know how many rows in result set after executing the particular query
我想知道执行特定查询后结果集中有多少行
ResultSet rs = ps.executeQuery();
how get the size of rs??? thanx in advance
如何获得rs的大小???提前谢谢
采纳答案by jester
If you just want the number of rows in the ResultSet
, you can do :
如果您只想要 中的行数ResultSet
,则可以执行以下操作:
int size= 0;
if (rs != null)
{
rs.beforeFirst();
rs.last();
size = rs.getRow();
}
回答by Baby
by doing while loop:
通过执行while循环:
int size=0;
while (rs.next()) {
size++;
}
回答by shikjohari
You need not to iterate it and count the number of rows. You can try the following easy approach
您不需要迭代它并计算行数。您可以尝试以下简单的方法
boolean b = rs.last();
int numberOfRecords = 0;
if(b){
numberOfRecords = rs.getRow();
}