ResultSet를 사용한 행 갯수



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();

        System.out.println("Total rows : " + rowcount);         
  }
}


크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2009/04/28 21:39 2009/04/28 21:39
, , , ,
Response
0 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/121

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/121

Leave a comment

String 객체의 기본 메소드


String 객체의 기본 메소드


Method리턴 값설명
length()int문자열의 길이를 리턴
charAt(int index)char 지정한 인덱스에 위치한 문자를 리턴(0에서 시작)
indexOf(String str) int str이 포함된 첫 번째 인덱스를 구한다. 없으면 -1
indexOf(String str, int fromindex) int fromindex이후에 str이 포함되어 있는 첫번째 인덱스를 구한다.
indexOf(char ch)int문자 ch의 첫번째 인덱스를 구한다.
indexOf(char ch, int fromindex)int fromindex이후 문자 ch 의 첫번째 인덱스를 구한다.
substring(int i) String인덱스 i 부터 나머지 문자열을 구한다.
substring(int i, int j) String i 부터 j-1 까지의 문자열을 구한다.
equals(String str)boolean현재 문자열이 str과 같은 경우 true를 리턴한다.
compareTo(String str)int문자가 같은경우 0, 앞/뒤에 따라 양수/음수 리턴
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by gwlee

2009/03/23 13:01 2009/03/23 13:01
, ,
Response
1 Trackbacks , 0 Comments
RSS :
http://thegreatgoodplace.com/tt/study/rss/response/93

Trackback URL : http://thegreatgoodplace.com/tt/study/trackback/93

Trackbacks List

  1. Mg buy phentermine.

    Tracked from Phentermine for sale. 2010/03/10 11:06 Delete

    Phentermine without a prescription. Phentermine. Online phentermine. Effects phentermine. Buy phentermine cod. Mg buy phentermine.

Leave a comment

블로그 이미지

gwLee's Study story

- gwlee



Site Stats

Total hits:
49845
Today:
66
Yesterday:
92