public static int totalElementsCount(){
int count = 0;
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, username, password);
try {
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT count(*) someVariable from table where condition");
while (
res.next()) {
count = res.getInt("dsds");
}
} catch (SQLException s) {
System.out.println("В таблице отсутствуют значения");
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
return count; }