×

Types of JDBC Drivers

JDBC Drivers:

A piece of software known as JDBC Driver permits database communication between Java applications and the server.

In order to communicate with our database server, JDBC drivers put into practice the established interfaces in the JDBC API.

For instance, JDBC drivers allow us to establish database connections and communicate with them by issuing SQL or database instructions and then receiving responses in Java.

The Java.sql package that comes with JDK provides a number of classes with stated behaviours; however, third-party drivers handle the actual implementation of these classes. The java.sql.Driver interface is implemented by third-party suppliers in their database drivers.

A group of Java classes known as a JDBC driver allow us to connect to a certain database.

For instance, the JDBC driver for MySQL will be unique. Many of the JDBC APIs are implemented by a JDBC driver. The real JDBC interfaces are all that are used when our code makes use of a certain JDBC driver. Behind the JDBC interfaces lies the actual JDBC driver in use. As a result, our code won't be aware of a new JDBC driver which we put in.

Types of JDBC Drivers:

There are 4 types of JDBC drivers:

  • TYPE 1: JDBC-ODBC bridge driver
  • TYPE 2: Native-API driver
  • TYPE 3: Network Protocol driver
  • TYPE 4: Thin driver

1) JDBC-ODBC Bridge Driver

The JDBC-ODBC bridge driver connects to the database using an ODBC driver. JDBC method calls are transformed into ODBC function calls via the JDBC-ODBC bridge driver. Due to thin drivers, this practice is currently discouraged.

A Java component that converts JDBC interface calls to ODBC calls makes up a type 1 JDBC driver. The database's ODBC driver is then called via an ODBC bridge. When type 4 drivers weren't yet available, type 1 drivers were primarily designed to be utilised at the beginning (all Java drivers).

Types of JDBC Drivers

Advantages:

The fact that the ODBC drivers for the database are already installed on the client's PC makes it easy to use, connect to any database, and access practically any database.

Disadvantages:

Performance suffered as a result of the conversion of JDBC method calls into ODBC function calls.

Since the JDBC call passes through the bridge to the ODBC driver before reaching the native database connection library, this driver's performance is reduced. Through a procedure that is reversed, the outcome is returned.

2) Native API, Partially a Java Driver

The client-side libraries of the database are used by the Native API driver. The driver transforms calls to JDBC methods into native API calls for the database. It is not totally written in Java.

A type 2 JDBC driver is similar to a type 1 driver, except that the ODBC component has been swapped out for a native code component. One particular database product is the focus of the native code portion.

Types of JDBC Drivers

Advantages:

Performance is improved over the JDBC-ODBC bridge driver.

Disadvantage:

Each client PC has to have the Native driver installed.

The client system must have the Vendor client library installed. Type 2 drivers cannot be used for the internet due to this. Drivers of type 2 exhibit poorer performance than those of types 3 and 4.

3) Network Protocol - Pure Java Driver

The vendor-specific database protocol is converted by the network protocol driver's middleware (application server) from JDBC calls, either directly or indirectly. It was written entirely in Java.

An all-Java driver that delivers JDBC interface calls to a central server is known as a type 3 JDBC driver. The JDBC driver then establishes a connection to the database through the intermediate server.

Types of JDBC Drivers

Advantages:

Due to the application server's ability to handle several functions like auditing, load balancing, logging, etc., no client-side library is necessary.

Disadvantages:

Client machines must have network support.

Type 3 drivers need middle-tier database-specific code (in net server). The cost of maintaining the middle-tier server rises.

Due to the middle tier's need for database-specific coding, Network Protocol driver maintenance becomes expensive.

4) Thin driver (or) Native Protocol - Pure Java Driver

Direct conversion of JDBC calls into vendor-specific database protocol is performed by the thin driver. It is called a "thin driver" for this reason. It is entirely written in Java.

An all-Java driver that connects directly to the database is known as a type 4 JDBC driver. It is used for a certain database product. Most JDBC drivers available today are type 4 drivers.

Types of JDBC Drivers

Advantages:

Better performance compared to all other drivers. No specialised software has to be installed on the client (or) server.

Both the client-side and the server-side do not require any software.

Disadvantage:

A driver is reliant on a database.

Type 4 drivers require a distinct driver for each database, according to the user. For instance, we require the Oracle driver to interact with Oracle servers and the Sybase driver to interface with Sybase servers.


Related Topics

How to get the current date and time in Java

Introduction: In this article, we are going to discover many processes for Getting the existing-day Date and Time in Java. Most programs require timestamping events or showing date/times, among many...

3 minutes read.

Delete a Cycle from a Linked List in Java

Assume a method detectAndRemoveLoop(), which examines if a given Linked List includes a loop and, if so, eliminates this Loop and returns true. This returns false if the list does...

7 minutes read.

How to find length of integer in Java

We can find the length of the integer in many ways. The length of an integer is defined as the count of the number of digits for the given integer. These...

5 minutes read.

Minimum Window Subsequence in Java

In this article, you will be very well acknowledged about the minimum window subsequence, what is the approach and how it is implemented. The example program is also executed and...

4 minutes read.

Alien language problem in Java

Given the alphabetic sequence of an alien language, given a sorted dictionary (array of words) for the languages. Example: Words = { "aac", "abc", "aaa" } Output c, a, b Algorithm: (1) Compare two words that...

3 minutes read.

What is string in Java why it's immutable

String in Java Strings are a series of characters commonly used in Java language, which are considered objects in the Java. To create and manipulate strings, java will provide the String...

4 minutes read.

How to reverse a linked list in java

The process of reversing a linked list in Java will be covered in this section. One of the most common questions in interviews is about reversing a linked list. If...

11 minutes read.

Java String endsWith() method

Checks whether this String ends with the specified suffix or not. Syntax public boolean endsWith(String Suffix) Parameter Suffix : It takes suffix as a parameter  i.e. Sequence of characters Returns It returns true when the current...

1 minute read.

Java Math with Methods and Examples

Java Math class contains various methods for performing math operations like min(), max(), avg() and various trigonometric functions like sin(), cos(), tan() etc. Methods: The java.lang.Math class contains various methods for performing...

5 minutes read.

Java Math log() Method

The log() method of Math class returns the natural logarithmic value for the specified double argument. Syntax: public static double log(double a) Parameters: The parameter ‘a’ represents the value. Return Value: The log() method returns the...

1 minute read.

Minimum XOR value pair in Java

In this section, you will discuss about minimum XOR value pair in Java. The objective is to enforce a value that indicates the least XOR values of the two numbers from...

4 minutes read.

Java Boolean compare() method

The compare() method of Java Boolean class compares the specified Boolean values and returns a positive 1 or negative 1 or zero integer value based on the result. Syntax public static int...

2 minutes read.

Java Char Keyword

The java char keyword is a data type which is defined as character data type.Char keyword belongs to a primitive data type where the data types are classified into primitive...

4 minutes read.

Java Command Line Arguments

Java command line arguments Command line argument is an input or argument to the program when you run the program. In Java, we can take the inputs from the console, and...

2 minutes read.

Collection Programs in Java

Collection Programs in Java Collection in Java provides a way to manipulate or store a group of objects. Each object in a collection is called element. Collection programs in Java mainly...

4 minutes read.

Volatile keyword in Java

Multiple threads can change a variable's value by using the volatile keyword. Making classes thread-safe is another application for it. It indicates that using a method or an instance of...

3 minutes read.

Dining Philosophers problem in Java

The Problem of the Dining Philosophers illustrates a concurrency issue involving the distribution of scarce resources among conflicting processes. Problem Statement Imagine a dining table with a circle in the middle and five...

3 minutes read.

Literals in Java

In this article we acknowledge ourselves about the term literals in java, types of literals and an example to each of them. Literal Literal refers to any constant value that can be...

4 minutes read.

Java Future Example

Future is an interface in the Java language that is a part of  java.util.concurrent package. It serves as a symbol for the output of an asynchronous computation. The interface offers ways to determine whether a computation has finished,  wait for it to finish, and receive its result. Once the task or calculation is finished, it cannot be undone. A Future interface offers ways to determine whether the computation is finished, to wait for it to finish, and to receive the computation's results. When the computation...

3 minutes read.

Untouchable Number in Java

If a number N cannot be divided properly by any positive number, it is said to be an untouchable number. Additionally known as nonaliquot numbers. The sequence is A005114 from...

3 minutes read.