Fetching single row result without iterating in loop from Mysql using Java

与世无争的帅哥 提交于 2019-12-11 11:04:33

问题


I have a simple query that returns only count of rows.

select count(*) cnt from table

I can read it by iterating through resultset.

like

while(rs.next()){
  int rowCount= rs.getInt(cnt);
}

But is there any way,using which I can get count directly without looping.


回答1:


How about:

int rowCount = rs.next() ? rs.getInt(cnt) : -1;

It doesn't save you much though



来源:https://stackoverflow.com/questions/21476777/fetching-single-row-result-without-iterating-in-loop-from-mysql-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!