Nearby lessons

7 of 37

JDBC - The Four Driver Types

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

In simple words: All JDBC drivers fall into one of four types based on how they convert Java calls. Type-1 uses ODBC, Type-2 uses native libraries, Type-3 uses a middleware server, and Type-4 talks to the database directly.
Trainer's Note: A company called Progress DataDirect introduced a Type-5 driver, but it is not an industry-recognised type. So we always study the four standard types.
Example01
JCode Cell
11) Type-1 -> JDBC-ODBC Bridge Driver (Bridge Driver)
22) Type-2 -> Native API - Partly Java Driver (Native Driver)
33) Type-3 -> All Java Net Protocol Driver (Network / Middleware Driver)
44) Type-4 -> All Java Native Protocol Driver (Pure Java / Thin Driver)

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.

In simple words: Type-1 converts twice: JDBC calls → ODBC calls → database calls. Two conversions make it the slowest driver, and since it needs ODBC (which is Windows-only), it was removed from JDK 8.

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.
Trainer's Note: Updated knowledge: because of these problems, the JDBC-ODBC bridge was removed from JDK 8. Many old books (including the classic one this material is based on) use it in examples — but today it simply will not run. We replace every such example with the modern Type-4 driver in this material.
Example02
JCode Cell
1Java App -> Type-1 Driver -> ODBC Driver -> Database

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).
Trainer's Note: Type-2 is the only driver that is both platform dependent AND database dependent — so it is not recommended.
Example03
JCode Cell
1Java App -> Type-2 Driver -> Vendor Native Libraries -> Database

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.
Trainer's Note: Type-3 is the only driver that is both platform independent AND database independent — good for large enterprise applications that use multiple databases.
Example04
JCode Cell
1Java App -> Type-3 Driver -> Middleware Server -> Database
2 
3(2-tier architecture for Types 1, 2, 4; 3-tier architecture for Type-3)

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.

In simple words: Type-4 talks to the database directly with no middleman — no ODBC, no native libraries, no middleware. Only Java is needed, so it is pure and thin, and direct talk makes it the fastest 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.
Trainer's Note: Type-4 is the recommended driver for almost all applications today. In this whole material, every example uses a Type-4 driver (MySQL Connector/J or Oracle thin driver).
Example05
JCode Cell
1Java App -> Type-4 Driver -> Database

The Four Drivers — Master Comparison Table

PropertyType-1Type-2Type-3Type-4
Converts JDBC calls toODBC callsNative library callsMiddleware callsDatabase calls directly
Implemented inJava + NativeJava + NativeJava onlyJava only
Architecture2-tier2-tier3-tier2-tier
Platform independent?NoNoYesYes
Database independent?YesNoYesNo
Thin or thick?ThickThickThickThin
SpeedSlowestFastMediumFastest

Thin vs Thick Driver

TypeMeaningExamples
Thin driverNeeds NO extra component to talk to the databaseType-4
Thick driverNeeds 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.
Trainer's Note: Trainer's advice: in real projects you will almost always use a Type-4 driver (like com.mysql.cj.jdbc.Driver or oracle.jdbc.OracleDriver). Just know the other three for exams and interviews.
📝 Key Takeaways
  • 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.

🧠 Test Your Knowledge

10 Questions
Progress: 0 / 10