I am implementing Paging in my application. For this I run a query and get a ResultSet.
Now I want to get total number of records in this ResultSet for my paging calculation.
How can I get this ? I don't want to execute extra SQL which gives me total rows.
Another option is to add the count aggregation as a sub queried column in your query. If your database is just a little bit smart, it will only execute that once. You should be able to check this easily using the query analyzer in your favorite database.
SELECT id,username,(SELECT COUNT(id) FROM users) FROM users;