Nearby lessons

6 of 37

JDBC - The JDBC API

📌 What You Will Learn
  • 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

The JDBC API is a fundamental part of database programming with JDBC. This lesson explains JDBC API — The Two Packages and The JDBC API at a Glance — Memory Map with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

JDBC API — The Two Packages

The JDBC API defines two packages:

1) java.sql — the basic package

Contains the core classes and interfaces for database communication. The most important ones:

InterfacesClasses
DriverDriverManager
ConnectionDate, Time, Timestamp
StatementDriverPropertyInfo
PreparedStatementTypes
CallableStatementSQLException
ResultSetSQLWarning
ResultSetMetaDataSavepoint
DatabaseMetaData
Blob, Clob

2) javax.sql — the extended package

Contains advanced features used mostly in enterprise applications:

Interface / classPurpose
DataSourceThe modern way to get connections (replaces DriverManager)
ConnectionPoolDataSourceFor connection pooling
RowSetA more flexible ResultSet
XADataSourceFor distributed (XA) transactions
Trainer's Note: Updated knowledge: in real applications today, we prefer DataSource (via connection pools like HikariCP) over DriverManager.getConnection(). But DriverManager is perfect for learning — every concept carries over.

The JDBC API at a Glance — Memory Map

Example02
JCode Cell
1java.sql javax.sql
2 DriverManager DataSource
3 Connection Statement ConnectionPoolDataSource
4 PreparedStatement RowSet
5 CallableStatement XADataSource
6 ResultSet
7 DatabaseMetaData / ResultSetMetaData
8 Blob / Clob / Date / Time / Timestamp
9 SQLException / SQLWarning
📝 Key Takeaways
  • 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.

🧠 Test Your Knowledge

4 Questions
Progress: 0 / 4