JDBC in Spring Boot Architecture
Fast recall
Quick revision
Core answer
application.properties; on top of it you use Spring Data JPA / Hibernate (or JdbcTemplate), which ultimately issue JDBC calls through that DataSource to the database.Whether you understand JDBC is the foundation under Spring's data abstractions.
Thinking JPA/Hibernate bypass JDBC, or that you wire DataSource manually.
Trace the layers: Repository → JPA/Hibernate → DataSource (Hikari) → JDBC driver → DB.
Interview-ready guide
Interview answer
In a typical Spring Boot application, JDBC sits right at the bottom of the data access layer; Spring doesn't replace JDBC, it layers convenient abstractions on top of it.
properties, Spring Boot auto-configures a connection pool DataSource for you, and by default that's HikariCP. You almost never wire it up by hand. On top of that DataSource, your code works with a high-level abstraction.
Most commonly that's a Spring Data JPA repository, where you just declare an interface method like findByCity and Hibernate generates the SQL. Hibernate, in turn, uses the DataSource to get a JDBC connection and runs the query through the JDBC driver. If you want something closer to raw SQL with less boilerplate, you can use JdbcTemplate, which is a thin Spring wrapper directly over JDBC.
So the request flows down through layers: a controller calls a service, the service calls a repository, the repository goes through Hibernate or JPA, which goes through the DataSource pool, which hands out a JDBC connection, and the driver finally talks to the database. The key insight is that even when you're writing JPA repositories and never see a Connection object, JDBC is still doing the actual work underneath.
JDBC in Spring Boot Architecture
Direct Answer
In a typical Spring Boot app, JDBC sits at the bottom of the data layer. Spring auto-configures a pooled DataSource (HikariCP) from application.properties; on top of it you use Spring Data JPA / Hibernate (or JdbcTemplate), which ultimately issue JDBC calls through that DataSource to the database.
Deep Dive & Architecture
Spring Boot first creates a DataSource from explicit application configuration and classpath conditions. In the usual JDBC starter, HikariCP provides the pool. Borrowing a Connection from that pool is different from opening a brand-new database socket for every repository call; closing the connection returns it to the pool.
JdbcTemplate works directly above JDBC. It obtains a connection, prepares and executes SQL, turns each ResultSet row into an application value, translates many SQLException values into Spring's data-access exception hierarchy, and releases resources. Application code still owns the SQL and row mapping.
JPA adds another layer. A Spring Data repository delegates to a JPA provider such as Hibernate, which maps entity operations to SQL. The provider still reaches the database through JDBC and the same DataSource. That means pool exhaustion, transaction boundaries, database locks, and slow SQL remain relevant even when no repository method contains JDBC code.
For a request such as GET /orders/42, the useful trace is controller → service → repository or template → transaction-bound connection → JDBC driver → database. The return path maps rows or entities back to the service and response. The abstraction changes who writes SQL and mapping code; it does not remove the database protocol beneath it.
Code Example
# application.properties — Spring builds a HikariCP DataSource from this
spring.datasource.url=jdbc:mysql://localhost:3306/shop
spring.datasource.username=app
spring.datasource.password=secret
@Repository
interface UserRepository extends JpaRepository<User, Long> {
List<User> findByCity(String city); // Hibernate -> JDBC -> SQL under the hood
}
// Or drop to JdbcTemplate for raw-ish JDBC with less boilerplate:
// jdbcTemplate.query("SELECT * FROM users WHERE city = ?", rowMapper, city);
Common Mistakes & Pitfalls
Thinking JPA/Hibernate bypass JDBC, or that you wire DataSource manually.
Check your understanding
Answer these without looking back at the article.
- What is JDBC and why does it exist? It provides a standard Java API for connecting to relational databases, executing SQL, and processing results without vendor-specific code.
- What is JDBC and what is its role in Java?
- What are the main components of the JDBC API?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.