JDBC Drivers
A JDBC driver is the piece of software that sits between your Java code and the actual database.
Your program only ever calls standard JDBC interfaces like Connection and Statement — it
has no idea how MySQL, PostgreSQL, or Oracle actually talk over the network. The driver's job is to translate those
standard JDBC calls into whatever network protocol the specific database understands, and translate the responses
back into JDBC objects your code can use.
The Four Driver Types
When JDBC was first designed, Sun defined four categories of drivers based on how much native (non-Java) code they relied on. Only one of these categories is actually used today, but the classification still shows up in textbooks and interview questions, so it's worth knowing.
| Type | Name | How it works today |
|---|---|---|
| Type 1 | JDBC-ODBC Bridge | Routed JDBC calls through an ODBC driver. Obsolete — removed from the JDK since Java 8 and never used in modern projects. |
| Type 2 | Native-API Driver | Part Java, part native (C/C++) client library specific to the database. Rare today; requires platform-specific binaries. |
| Type 3 | Network Protocol Driver | Pure Java, but talks to a middleware server that translates to the database's protocol. Rare; adds an extra hop. |
| Type 4 | Thin Driver | Pure Java, talks directly to the database over the network using its native protocol. No middleware, no native binaries. |
Real Type 4 Drivers You'll Actually Use
| Database | Driver | Driver class name |
|---|---|---|
| MySQL | MySQL Connector/J | com.mysql.cj.jdbc.Driver |
| PostgreSQL | PostgreSQL JDBC Driver (pgJDBC) | org.postgresql.Driver |
| Oracle | ojdbc (Oracle JDBC Driver) | oracle.jdbc.driver.OracleDriver |
Where the Driver Class Name Comes From
Every driver ships a class that implements java.sql.Driver. Historically you loaded it explicitly
with Class.forName(...) so the JVM would register it with DriverManager. The example
below shows the fully-qualified class name for the modern MySQL Connector/J driver:
Example: The MySQL Type 4 Driver Class Name
public class DriverNameExample {
public static void main(String[] args) throws Exception {
// Fully-qualified class name of the MySQL Connector/J Type 4 driver
Class.forName("com.mysql.cj.jdbc.Driver");
}
}