SQL 문 (COUNT()) 에 의한 Row 갯수
public class count {
public static void main(String[] args) throws Exception {
String jdbcUrl = "jdbc:mysql://localhost:3306/"+database;
String dbId = id;
String dbPass= passwd;
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(jdbcUrl,dbId,dbPass);
Statement stmt = conn.createStatement();
int rowcount = 0;
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM employee_tbl");
if(rs.next()) {
rowcount = rs.getInt(1);
}
System.out.println("Total rows : " + rowcount);
}
}
ResultSet에 검색된 결과에 의한 Row 갯수
public class count {
public static void main(String[] args) throws Exception {
String jdbcUrl = "jdbc:mysql://localhost:3306/"+database;
String dbId = id;
String dbPass= passwd;
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(jdbcUrl,dbId,dbPass);
Statement stmt = conn.createStatement();
int rowcount = 0;
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM employee_tbl");
rs.last();
int rowcount = rs.getRow();
rs.beforeFirst();
}
}
Posted by gwlee