问题
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