package WBSer_RwCnt; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Rw_Count { public static int countRows() throws SQLException { // select the number of rows in the table Statement stmt = null; ResultSet rs = null; String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost/hospital_data"; String username = "root"; String password = "mysql"; try { Class.forName(driver); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // load MySQL driver Connection conn = DriverManager.getConnection(url, username, password); int rowCount = -1; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT COUNT(*) FROM hospital_status"); // get the number of rows from the result set rs.next(); rowCount = rs.getInt(1); }catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { rs.close(); stmt.close(); conn.close(); } return rowCount; } }