Tag Archives: JDBC Driver adavantages

JDBC: Drivers Types and Uses


JDBC Driver is a interface that enables JAVA application to interact with the database. The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database.

There are 4 types of JDBC drivers:

  1. Type 1: JDBC-ODBC bridge driver
  2. Type 2: Native-API driver (partially java driver)
  3. Type 3: Network protocol driver (fully java driver)
  4. Type 4: Thin driver (fully java driver)

Type 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 call (local native code). This is now discouraged because of thin driver.

JDBC-ODBC Bridge driver is not multi threaded  which uses synchronized methods to serialize all the calls made to ODBC.

JDBC-ODBC Bridge can open only one Statement object per connection.

JDBC Type 1-JDBC ODBC Bridge Driver

When to use?

The type 1 driver is not considered a deployment-level driver and is typically used for development and testing purposes only.

Advantage

  • easy to use.
  • Easily connected to any database

Disadvantage

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

Type 2: Native-API driver (partially java 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.

JDBC Type 2-Native API Driver

When to use?

Type 2 drivers are useful in situations where a type 3 or type 4 driver is not available yet for your database.

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.

Type 3: Network protocol driver (fully java 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.

JDBC Type 3 - Network Protocol Driver

When to use?

If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.

Advantage

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

Disadvantage

  • 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.

Type 4: Thin driver (fully java driver)

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

JDBC Type 4 - Thin Driver Pure Java

When to use?

If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is 4.

Advantage

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

Disadvantage

  • Drivers depend on the database.

Note : Type 4 thin driver is fastest JDBC driver written in JAVA.

Some important questions and answers for generally asked in interview when interviewer want to check depth knowledge of interviewee.

What do you mean by fastest driver? Which type of JDBC driver is the fastest one?

JDBC driver performance or fastness depends on a number of issues Quality of the driver code, size of the driver code, database server and its load, Network topology, Number of times your request is translated to a different API.

Type 4: Thin driver (fully Java driver) is the fastest driver because it converts the JDBC calls into vendor specific protocol calls and it directly interacts with the database.

Is it possible to connect to multiple databases? Using single statement can we update or extract data from two or three or many databases?

Yes, it is possible to connect to multiple databases, at the same time, but it depends on the specific driver.

To update and extract data from the different database we can use the single statement. But we need middleware to deal with multiple databases or a single database.

How does JDBC handle the data types of Java and database?

The JDBC driver converts the Java data type to the appropriate JDBC type before sending it to the database. It uses a default mapping for most data types. For example, a Java int is converted to an SQL INTEGER.

More on JDBC

Follow below links to know more on JDBC and solving JDBC issues :

JDBC Tutorial

JDBC Sample Code

JDBC Issues and Solutions

JDBC Interview Questions And Answers

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!