JDBC Driver

JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers:
  1. JDBC-ODBC bridge driver
  2. Native-API driver (partially java driver)
  3. Network Protocol driver (fully java driver)
  4. Thin driver (fully java driver)

1) JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls. This is now discouraged because of thin driver.
bridge driver

In Java 8, the JDBC-ODBC Bridge has been removed.

Oracle does not support the JDBC-ODBC Bridge from Java 8. Oracle recommends that you use JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge.

Advantages:

  • easy to use.
  • can be easily connected to any database.

Disadvantages:

  • Performance degraded because JDBC method call is converted into the ODBC function calls.
  • The ODBC driver needs to be installed on the client machine.

2) Native-API driver

The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API. It is not written entirely in java.
Native-API driver

Advantage:

  • performance upgraded than JDBC-ODBC bridge driver.

Disadvantage:

  • The Native driver needs to be installed on the each client machine.
  • The Vendor client library needs to be installed on client machine.

3) Network Protocol driver

The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or indirectly into the vendor-specific database protocol. It is fully written in java.

Network Protocol driver

Advantage:

  • No client side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc.

Disadvantages:

  • Network support is required on client machine.
  • Requires database-specific coding to be done in the middle tier.
  • Maintenance of Network Protocol driver becomes costly because it requires database-specific coding to be done in the middle tier.

4) Thin driver

The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is known as thin driver. It is fully written in Java language.
Thin driver

Advantage:

  • Better performance than all other drivers.
  • No software is required at client side or server side.

Disadvantage:

  • Drivers depend on the Database.


JDBC driver MCQ

1. Which type of JDBC driver is known as the "Pure Java" driver and directly converts JDBC calls to database-specific calls?

  1. Type 1
  2. Type 2
  3. Type 3
  4. Type 4

Answer: D)

Explanation: Type 4 drivers are known as "Pure Java" drivers because they are implemented entirely in Java and convert JDBC calls directly into database-specific calls.


2. Which JDBC driver type uses native code and is platform-dependent, making it less portable?

  1. Type 1
  2. Type 2
  3. Type 3
  4. Type 4

Answer: B)

Explanation: Type 2 drivers use native libraries specific to the database, making them dependent on the platform and less portable.


3. Which of the following JDBC driver types is considered the most flexible but also the slowest due to the number of translations needed?

  1. Type 1
  2. Type 2
  3. Type 3
  4. Type 4

Answer: A)

Explanation: Type 1 drivers are bridge drivers that convert JDBC calls to ODBC calls, which are then translated to database-specific calls. Due to multiple layers of translation, they are the slowest drivers.


4. What is the main disadvantage of using a Type 3 JDBC driver in a three-tier architecture?

  1. Lack of portability
  2. Slower performance due to multiple translations
  3. Dependency on native libraries
  4. Complex configuration and maintenance

Answer: D)

Explanation: Type 3 drivers use a middleware server that translates JDBC calls to database-specific calls, making configuration and maintenance more complex.


5. Which JDBC driver type is most suitable for web applications that need to be platform-independent?

  1. Type 1
  2. Type 2
  3. Type 3
  4. Type 4

Answer: D)

Explanation: Type 4 drivers are entirely written in Java, making them platform-independent and suitable for web applications that require high portability.