DAO 클래스(미완성)

BEHE_LIT·2020년 3월 2일
0

Java공부

목록 보기
19/19

Connection 인터페이스

Why? 왜 필요한가?

특정 데이터베이스와의 연결(세션)

What?

  • SQL문이 실행됨 + 결과를 연결 컨텍스트 내에서 반환.
    (컨텍스트란? 객체를 핸들링하기 위한 접근수단)
  • 연결객체의 데이터베이스가 역할을 수행하도록 한다.

    데이터베이스의 역할
    A Connection object's database is able to provide information describing its tables, its supported SQL grammar, its stored procedures, the capabilities of this connection, and so on. This information is obtained with the getMetaData method.

@CallerSensitive  //getConnection 메소드 코드
    public static Connection getConnection(String url,
        String user, String password) throws SQLException {
        java.util.Properties info = new java.util.Properties();

        if (user != null) {
            info.put("user", user);
        }
        if (password != null) {
            info.put("password", password);
        }

        return (getConnection(url, info, Reflection.getCallerClass()));
    } // 리턴값으로 SQL문을 Java 데이터로 변경하는 과정인듯?

풀어야할 숙제

  • Connection과 DriverManager의 관계
  • Properties클래스
  • Reflection클래스 - 메서드 : Reflection.getCallerClass() -> 뜯어보려했으나 실패

PreparedStatement 인터페이스

Why? 왜 필요한가?

미리컴파일된 SQL문을 나타내기 위해

What?

  • SQL문이 PreparedStatement 객체에 미리 컴파일되고 저장된다.
  • PreparedStatement 객체는 SQL문을 여러번 유용하게 실행시킬 수 있다.

ResultSet 인터페이스

Why? 왜 필요한가?

쿼리문의 실행결과로 인해 생성되는 데이터베이스 집합을 나타내기 위해

What?

  • 현재 데이터행을 가리키는 커서를 유지관리
  • next메소드 필수
profile
방랑자의 현장에 오신걸 환영합니다.

0개의 댓글