Get a record count with a SQL StatementTag(s): JDBC
About cookies on this site
We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM MyTable");
r.next();
int count = r.getInt("rowcount") ;
r.close() ;
System.out.println("MyTable has " + count + " row(s).");
JDBC 2.0 provides a way to retrieve a rowcount from a ResultSet without
having to scan through all the rows or issue a separate SELECT COUNT(*).
Statement s = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet r = s.executeQuery
("SELECT * FROM employee WHERE id_emp LIKE '1%'");
r.last();
int count = r.getRow();
r.beforeFirst();
...
NOTE : Your JDBC driver may not support this feature.