Nearby lessons
7 of 37JDBC - The Four Driver Types
- The four types of JDBC drivers
- Advantages and limitations of each type
- Thin driver vs Thick driver
- 2-Tier vs 3-Tier architecture
- Which driver to choose in which situation
The Four Driver Types is a fundamental part of database programming with JDBC. This lesson explains Why Four Types?, Type-1 Driver — JDBC-ODBC Bridge and Type-2 Driver — Native API Driver with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Why Four Types?
To talk to a database, Java calls must be converted into database-specific calls. Driver software does this conversion. There are thousands of driver products in the market, but on the basis of how they do the conversion, all of them fall into four types:
Type-1 Driver — JDBC-ODBC Bridge
This driver was provided by Sun as part of the JDK itself (up to Java 1.7 only). It does not talk to the database directly — it first converts JDBC calls into ODBC calls, and the ODBC driver then converts them into database calls.
Advantages
- Very easy to use and maintain.
- No separate software to install — it came with the JDK.
- Database independent — changing databases is easy.
Limitations
- The slowest driver (two conversions: JDBC→ODBC→database).
- Platform dependent — it needs ODBC, which works only on Windows.
- No support from JDK 1.8 onwards — it was removed.
Type-2 Driver — Native API Driver
Type-2 is the same idea as Type-1, but instead of the ODBC driver it uses the vendor's own native libraries (mostly C/C++ functions) to talk to the database. You must install those native libraries on the client machine.
Example: Oracle's OCI (Oracle Call Interface) driver — it uses C-language OCI libraries. The driver comes in JAR files like ojdbc14.jar (Oracle 10g), ojdbc6.jar (Oracle 11g), ojdbc7.jar (Oracle 12c).
Advantages
- Faster than Type-1 (only one conversion: JDBC → native calls).
- No ODBC driver needed.
Limitations
- Database dependent — changing databases is difficult.
- Platform dependent.
- Must install native libraries on every client machine.
- Not every database vendor provides this driver (MySQL does not).
Type-3 Driver — Network Protocol / Middleware Driver
Type-3 converts JDBC calls into middleware server calls. The middleware server (like an IDS — Internet Database Access Server) then talks to the database, possibly using a Type-1, 2 or 4 driver internally.
Advantages
- Platform independent.
- Database independent.
- No ODBC driver or native libraries needed.
Limitations
- Performance may drop because of the middleware server in the middle.
- You must purchase the middleware server — it is costly.
Type-4 Driver — Pure Java / Thin Driver
Type-4 talks to the database directly, using the database's own native protocol. It needs no ODBC, no native libraries, no middleware. It is written only in Java — hence pure Java driver — and it needs no extra components on the client — hence thin driver.
Examples: Oracle thin driver, MySQL Connector/J driver.
Advantages
- No extra components needed — light weight (thin).
- Platform independent.
- More secure (uses the vendor's native protocol).
Limitation
- Database dependent — each database needs its own driver.
The Four Drivers — Master Comparison Table
| Property | Type-1 | Type-2 | Type-3 | Type-4 |
|---|---|---|---|---|
| Converts JDBC calls to | ODBC calls | Native library calls | Middleware calls | Database calls directly |
| Implemented in | Java + Native | Java + Native | Java only | Java only |
| Architecture | 2-tier | 2-tier | 3-tier | 2-tier |
| Platform independent? | No | No | Yes | Yes |
| Database independent? | Yes | No | Yes | No |
| Thin or thick? | Thick | Thick | Thick | Thin |
| Speed | Slowest | Fast | Medium | Fastest |
Thin vs Thick Driver
| Type | Meaning | Examples |
|---|---|---|
| Thin driver | Needs NO extra component to talk to the database | Type-4 |
| Thick driver | Needs an extra component (ODBC / native libraries / middleware) | Type-1, Type-2, Type-3 |
Which Driver Should You Use?
The classic material gives a clear decision rule:
- One database only (stand-alone or small web app) → use Type-4.
- Multiple databases (large enterprise app) → use Type-3.
- If Type-3 and Type-4 are not available → then Type-2.
- If no other driver is available → then Type-1.
- Four driver types: Type-1 (Bridge), Type-2 (Native), Type-3 (Network/Middleware), Type-4 (Thin).
- Type-1 (JDBC-ODBC bridge) is removed from JDK 8 — never use it today.
- Type-4 (pure Java thin driver) is the recommended modern choice.
- Thin driver = no extra component; Thick driver = needs ODBC/native/middleware.
- Types 1, 2, 4 are 2-tier; Type-3 is 3-tier.
- Decision: single DB → Type-4; multiple DBs → Type-3.