Home JDBC 란 무엇일까?
Post
Cancel

JDBC 란 무엇일까?

JDBC 란!

Java DataBase Connectivity 의 줄임말이다.

즉, Database 에 연결하고 쿼리를 수행하는 API 중 하나이다.

또한 JDBC는 적합한 드라이버가 제공된다면 모든 데이터베이스에서 작동할 수 있다.


JDBC Driver 란!

JDBC API 구현체로, 각각의 다른 타입을 가진 Database를 연결할 때 사용하는 것이다.

JDBC Driver 종류는?

Type 1 : 다른 데이터베이스 접근 API (ODBC 등)에 대한 매핑을 시킬 수 있다.

Type 2 : 대상 데이트베이스의 클라이언트 측 라이브러리를 사용하는 구현체이다.

Type 3 : 미들웨어를 사용하여 JDBC 호출을 특정 데이터베이스 호출로 변환한다. Network Protocol Driver 로 주로 쓰인다.

Type 4 : JDBC 호출을 특정 데이트베이스 호출로 변환하여 직접 데이터베이스에 연결한다. Database Protocol divers 로 주로 쓰인다.


JDBC Driver 사용하기

JDBC-공식문서

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public Connection getConnection() throws SQLException {

    Connection conn = null;
    Properties connectionProps = new Properties();
    connectionProps.put("user", this.userName);
    connectionProps.put("password", this.password);

    if (this.dbms.equals("mysql")) {
        conn = DriverManager.getConnection(
                "jdbc:" + this.dbms + "://" +
                this.serverName +
                ":" + this.portNumber + "/",
                connectionProps);
        } else if (this.dbms.equals("derby")) {
            conn = DriverManager.getConnection("jdbc:" + this.dbms + ":" +
                       this.dbName +
                       ";create=true",
                       connectionProps);
        }
        System.out.println("Connected to database");
        return conn;
    }

위 코드의 내용을 활용하여 Java 코드를 통해 Database를 접속할 수 있게 된다.

Spring Framework를 사용하면, Hibernate가 대신 JDBC 를 활용하여 DB와의 소통을 시작하게 해준다.


결론

Java 기반의 Framework 혹은, 순수 Java 코드로 DB에 접근하여 소통을 위해선 JDBC 를 활용해야하고,

가장 DB와 Layer 가 가까운 기술이라고 볼 수 있다.

This post is licensed under CC BY 4.0 by the author.