JDBC Architecture

What is JDBC

JDBC (Java Database Connectivity, package java.sql) is the standard API for SQL databases. Your code talks to JDBC interfaces; a driver jar from the database vendor implements them. Spring Data JPA, Hibernate, jOOQ and MyBatis all use JDBC underneath.

Your code ──► JDBC API (java.sql: Connection, PreparedStatement, ResultSet)
                 │
                 ▼
          JDBC driver (mysql-connector-j, postgresql, ojdbc11)
                 │  network protocol
                 ▼
          Database (MySQL, PostgreSQL, Oracle)

Core Interfaces

InterfaceRole
DriverManager / DataSourcegive you a Connection (DataSource = pooled, preferred)
Connectiona session with the DB; controls transactions
PreparedStatementprecompiled SQL with ? parameters
ResultSetcursor over the rows of a query
SQLExceptionchecked exception for all DB errors (getSQLState(), getErrorCode())

Driver Dependency

<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>8.4.0</version>
    <scope>runtime</scope>
</dependency>
<!-- PostgreSQL: org.postgresql:postgresql:42.7.4 -->

Note: Since JDBC 4 drivers register themselves automatically (ServiceLoader). Class.forName("com.mysql.cj.jdbc.Driver") is no longer needed.