HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🤩
개발
/
Spring Data
Spring Data
/
📌
Spring JDBC(Java Database Connectivity)
/
🎐
JDBC API (저수준 API)
🎐

JDBC API (저수준 API)

JDBCJDBC APIJDBC DB DriverJDBC Architecture modelJDBC Driver ModelJDBC Flow

JDBC

notion image
notion image
  • JDBC는 크게 두 개의 interface로 나뉘게 됨

JDBC API

  • application code가 database와 통신하기 위해 사용하는 공통적인 API임
  • Any DAO or repository implementation needs access to a persistence resource, depending on the persistence technology used
    • JDBC-based repository ⇒ needs access to a JDBC DataSource
    • JPA - based repository ⇒ needs access to an EntityManager
//JPA-based repository @Repository public class JpaMovieFinder implements MovieFinder { @PersistenceContext private EntityManager entityManager; // ... } //JDBC-based repository @Repository public class JdbcMovieFinder implements MovieFinder { private JdbcTemplate jdbcTemplate; @Autowired public void init(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } // ... } // DataSource injected into an initialization method or constructor for JdbcTemplate

JDBC DB Driver

 

JDBC Architecture model

notion image
  • JDBC API는 Application Code에서 사용하는 것이고 이 API를 통해 JDBC DB DRIVER와 Connection을 맺게 되고 DriverManager가 DB와 연결해서 데이터를 가져오게 됨
  • Connection에서 Statement통해서 데이터를 가져오면 그 데이터가 ResultSet이 됨. DriverManager부분이 DB와의 driver를 관리해주는 부분
  • maven이라면 pom.xml에 mysql driver에 대한 의존성을 추가해 주면, DriverManager에서 알아서 driver 찾아서 연결 후 connection 객체 반환해 줌

JDBC Driver Model

  1. Type I : JDBC- ODBC Bridge
  1. Type II: Native APT- Partly Java Driver
  1. Type III: Network Protocol- Fully Java Driver
  1. Type IV: Thin Driver- Fully Java Driver 우리가 사용할 MySQL에서도 type4용JDBC Driver를 제공합니다
notion image
 

JDBC Flow

https://www.javarticles.com/2015/01/spring-jdbctemplate-example.html
notion image
  • DriverManager 를 통해서 컨넥션 객체를 받아옵니다.
  • Connection을 통해서 Statement를 가져옵니다.
  • Statement를 통해서 쿼리를 실행해서 ResultSet을 가져오거나 update를 실행합니다.
  • 데이터베이스 커넥션을 종료합니다