Getting the Number of Rows in a Database Table

This example gets the number of rows in a table using the SQL statement `SELECT COUNT(*)'.
try { // Select the number of rows in the table Statement stmt = connection.createStatement(); ResultSet resultSet = stmt.executeQuery("SELECT COUNT(*) FROM my_table"); // Get the number of rows from the result set resultSet.next(); int rowcount = resultSet.getInt(1); } catch (SQLException e) { }

Comments

14 Jan 2010 - 7:27pm by xeno (not verified)

statement stmt = connection.createStatement();
errm wad does the connection in this statement refer to?

15 Jan 2010 - 1:37am by patrick

Here's some code that will create a connection:
http://exampledepot.com/egs/java.sql/ConnectMySql.html

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.