2011-04-26 7 views

답변

0

위에서 설명한 답변 외에도 JPA (최대 절전 모드)는 학습 곡선이라는 초기 장벽을 넘으면 (그리고 성능 최적화라고하는 다음 번에 치기 전에) 훨씬 더 쉽습니다. 진지한 점에서 예 JPA는 모든 데이터베이스를 동일한 방식으로 연결하고 쿼리하는 표준 방법이기도합니다.

0

JDBC가 표준 방법입니다. Hibernate

Connection con = null; 
    String driver = "com.mysql.jdbc.Driver"; 
    String url = "jdbc:mysql://localhost:3306/"; 
    String db = "testdb"; 
    String dbUser = "root"; 
    String dbPasswd = "mysql123"; 
    try{ 
    Class.forName(driver); 
    con = DriverManager.getConnection(url+db, dbUser, dbPasswd); 
    try{ 
    Statement st = con.createStatement(); 
    String sql = "DELETE FROM user WHERE email = '[email protected]'"; 
    int delete = st.executeUpdate(sql); 
    if(delete >= 1){ 
    System.out.println("Row is deleted."); 
    } 
    else{ 
    System.out.println("Row is not deleted."); 
    } 
    } 
    catch (SQLException s){ 
    System.out.println("SQL statement is not executed!"); 
    } 
    } 
    catch (Exception e){ 
    e.printStackTrace(); 
    } 
0

어쩌면 객체 관계형 매핑 당신을 위해 유용한 방법입니다 : 다음은 MySQL 데이터베이스를 연결하는 샘플 자바 코드입니다.

관련 문제