String query = "SELECT COUNT(*) AS count FROM table1";
ResultSet rs = DBConnection.executeQuery(query);
The above code works fine; however:
long count = rs.getLong("count");
This wont work, it throws SQLException. How should I get data from the ResultSet
?
COUNT() returns the number of items in a group, including NULL values and duplicates. COUNT(expression) evaluates expression for each row in a group and returns the number of non null values. Follow this answer to receive notifications.
The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.
execute : Returns true if the first object that the query returns is a ResultSet object. Use this method if the query could return one or more ResultSet objects. Retrieve the ResultSet objects returned from the query by repeatedly calling Statement.
The COUNT() function returns the number of records returned by a select query.
long tmpLong = rs.getLong(1);
should work from what I can recall.
EDIT:
of course:
rs.next();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With