Java中如何通过ResultSet获取行数 [英] How get the number of rows count by ResultSet in Java

查看:47
本文介绍了Java中如何通过ResultSet获取行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取 ResultSet 的行数.

ResultSet rs;
Statement s;
rs=s.executeQuery("SELECT * FROM mytable");

//rs.getRowCount; ???

推荐答案

你可以到结果集的最后一行,得到这样的行号:

You can go to the last row of the resultset and get the row number like this:

resultSet.last()
int count = resultSet.getRow()

但这效率低下,因为它必须读取所有表数据.最好执行查询:

But this is inefficient because it has to read all the table data. Better to execute the query:

SELECT COUNT(*) FROM mytable

这篇关于Java中如何通过ResultSet获取行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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