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

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.

Answers


How about:

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

It doesn't save you much though


Need Your Help

How to call CoreLocation from different Views

ios swift oop architecture core-location

I have Two Views (one table, one collection). In each View's Cell, there is a button that when tapped should get the user's current location and pass it into a variable to be used in a Deeplink.