Nearby lessons
5 of 37JDBC - Architecture
- The full JDBC architecture and how the parts connect
- DriverManager — the manager of all drivers
- Database Driver — the bridge
- The two JDBC packages: java.sql and javax.sql
- The important classes and interfaces of JDBC
Architecture is a fundamental part of database programming with JDBC. This lesson explains The JDBC Architecture, DriverManager — The Key Component and Database Driver — The Bridge with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
The JDBC Architecture
The JDBC architecture has four layers working together:
The beauty: because your program talks only to the JDBC API (and not directly to a database), you can change the database without changing your Java code — just swap the driver and the URL.
DriverManager — The Key Component
DriverManager is a Java class in the java.sql package. It is the manager of all the database drivers available in your system. Its three jobs:
| Job | Method used |
|---|---|
| Register a driver (add it to its list) | DriverManager.registerDriver(driver) |
| Unregister a driver (remove it) | DriverManager.unregisterDriver(driver) |
| Establish a connection using the right driver | DriverManager.getConnection(url, user, pwd) |
When you call getConnection(...), the DriverManager internally asks each registered driver: can you handle this URL? The first matching driver makes the connection.
Database Driver — The Bridge
A database driver is the software that sits between the Java application and the database. It is the most important piece: without a driver you cannot touch the database at all.
- It converts Java calls into database-specific calls.
- It converts database results back into Java objects.
Two important parallel ideas (excellent for interviews):
| Idea | Explanation |
|---|---|
| Java application is database independent, but the driver is database dependent | The driver's job is exactly to hide the database differences from your Java code. |
| Java application is platform independent, but the JVM is platform dependent | Because of the JVM, your program runs anywhere — same logic as above. |
- Architecture: Java app → JDBC API → DriverManager → Driver → Database.
- DriverManager registers drivers and creates connections.
- Driver is the bridge that converts Java calls to database calls and back.
- JDBC API = java.sql (basic) + javax.sql (advanced/enterprise).
- Key interfaces: Driver, Connection, Statement, PreparedStatement, CallableStatement, ResultSet.
- Modern apps use DataSource + connection pools instead of DriverManager.