DriverManager vs DataSource in JDBC
Fast recall
Quick revision
Core answer
Whether you know DataSource (pooled) is preferred over DriverManager (new connection each time).
Opening a new physical DriverManager connection for each request instead of using an appropriately configured DataSource/pool.
Note opening a physical connection is expensive; pooling via DataSource is why it matters.
Interview-ready guide
Interview answer
A command-line utility can use DriverManager.getConnection for a short-lived operation. A Spring service should normally inject a DataSource managed by configuration, which in Boot is commonly a Hikari pool. Tests can replace that bean without changing repository code. The advantage is managed configuration and an abstraction for acquisition; do not define DataSource as synonymous with a pool.
DriverManager vs DataSource in JDBC
Direct Answer
DriverManager is a static JDBC service that chooses a registered driver from a URL. DataSource is a configurable factory interface and is normally preferred for application integration, dependency injection, JNDI, and pool or XA support. A DataSource is often backed by a pool, but that is an implementation choice; it does not always reuse connections.
Common Mistakes & Pitfalls
Opening a new physical DriverManager connection for each request instead of using an appropriately configured DataSource/pool.
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.