怎样取得结果集的记录条数?

chenchen2003 2005-04-14 11:49:26
DriverManager.registerDriver(new OracleDriver());
Connection con = DriverManager.getConnection();
PreparedStatement stmt = con.prepareStatement("Select * from test where no = ?");
stmt.setString(1,"1");
ResultSet rs = stmt.executeQuery();
//取记录条数。
...全文
313 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kulama2004 2005-04-15
  • 打赏
  • 举报
回复
据我知道jdbc2.0还没有办法直接调,也许3.0可能有,但是现在大多数数据库的jdbc驱动都是兼容2.0标准的
另外你想得到设好值的sql,需要手动通过程序去获取
chenchen2003 2005-04-14
  • 打赏
  • 举报
回复
补充一下,不想用移动游标到最后去行号的方法。
最好有个getRows的方法。
chenchen2003 2005-04-14
  • 打赏
  • 举报
回复
除了用把游标移动到最后取行号方法外。
有方法直接可以调吗?我找了好久找不到。
另外问一下,
PreparedStatement stmt = con.prepareStatement("Select * from test where no = ?");
stmt.setString(1,"1");
对于预处理,我在set后,怎样才能取得设好值(不含有问号的)后的SQL文。
kulama2004 2005-04-14
  • 打赏
  • 举报
回复
Get a record count with the SQL Statement
Statement s = con.createStatement();
ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM MyTable");
r.next();
int ResultCount = r.getInt("rowcount") ;
r.close() ;


JDBC 2.0 provides a way to retrieve a rowcount from a ResultSet without having to scan through all the rows or issue a separate SELECT COUNT(*). Statement s =
conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet r =
s.executeQuery("SELECT * FROM employee WHERE id_emp LIKE '1%'");
r.last();
count = r.getRow();
r.beforeFirst();


kulama2004 2005-04-14
  • 打赏
  • 举报
回复
你可以把sql改成
select count(rowid) rowcount, test.* from test where no = ?
不然的话你只有用游标去获得行数

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧