Driver types in java

JDBC Driver Types

A JDBC driver is a set of Java classes that implement the JDBC interfaces, targeting a specific database. The JDBC interfaces comes with standard Java, but the implementation of these interfaces is specific to the database you need to connect to. Such an implementation is called a JDBC driver. JDBC drivers are typically supplied by the database vendor, but may sometimes be provided by the developer community around a database.

JDBC Driver Type List

There are four different JDBC driver types. These driver types are:

  • Type 1: JDBC-ODBC bridge JDBC driver
  • Type 2: Java + Native code JDBC driver
  • Type 3: All Java + Middleware translation JDBC driver
  • Type 4: All Java JDBC driver.

Today, most JDBC drivers are type 4 drivers. Nevertheless, I will just discuss the 4 types of JDBC drivers shortly.

Type 1 JDBC Driver

A type 1 JDBC driver consists of a Java part that translates the JDBC interface calls to ODBC calls. An ODBC bridge then calls the ODBC driver of the given database. Type 1 drivers are (were) mostly intended to be used in the beginning, when there were no type 4 drivers (all Java drivers). Here is an illustration of how a type 1 JDBC driver is organized:

Type 2 JDBC Driver

A type 2 JDBC driver is like a type 1 driver, except the ODBC part is replaced with a native code part instead. The native code part is targeted at a specific database product. Here is an illustration of a type 2 JDBC driver:

Type 3 JDBC Driver

A type 3 JDBC driver is an all Java driver that sends the JDBC interface calls to an intermediate server. The intermediate server then connects to the database on behalf of the JDBC driver. Here is an illustration of a type 3 JDBC driver:

Читайте также:  Python наследование классов конструктор

Type 4 JDBC Driver

A type 4 JDBC driver is an all Java driver which connects directly to the database. It is implemented for a specific database product. Today, most JDBC drivers are type 4 drivers. Here is an illustration of how a type 4 JDBC driver is organized:

Источник

JDBC Drivers

Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access any kind of tabular data, especially relational database. It is part of Java Standard Edition platform, from Oracle Corporation. It acts as a middle layer interface between java applications and database.

The JDBC classes are contained in the Java Package java.sql and javax.sql.
JDBC helps you to write Java applications that manage these three programming activities:

  1. Connect to a data source, like a database.
  2. Send queries and update statements to the database
  3. Retrieve and process the results received from the database in answer to your query

Structure of JDBC

JDBC Drivers

JDBC drivers are client-side adapters (installed on the client machine, not on the server) that convert requests from Java programs to a protocol that the DBMS can understand. There are 4 types of JDBC drivers:

  1. Type-1 driver or JDBC-ODBC bridge driver
  2. Type-2 driver or Native-API driver
  3. Type-3 driver or Network Protocol driver
  4. Type-4 driver or Thin driver

Type-1 driver

Type-1 driver or 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. Type-1 driver is also called Universal driver because it can be used to connect to any of the databases.

  • As a common driver is used in order to interact with different databases, the data transferred through this driver is not so secured.
  • The ODBC bridge driver is needed to be installed in individual client machines.
  • Type-1 driver isn’t written in java, that’s why it isn’t a portable driver.
  • This driver software is built-in with JDK so no need to install separately.
  • It is a database independent driver.
Читайте также:  Get width value css

Type-2 driver

The Native API driver uses the client -side libraries of the database. This driver converts JDBC method calls into native calls of the database API. In order to interact with different database, this driver needs their local API, that’s why data transfer is much more secure as compared to type-1 driver.

  • Driver needs to be installed separately in individual client machines
  • The Vendor client library needs to be installed on client machine.
  • Type-2 driver isn’t written in java, that’s why it isn’t a portable driver
  • It is a database dependent driver.

Type-3 driver

The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or indirectly into the vendor-specific database protocol. Here all the database connectivity drivers are present in a single server, hence no need of individual client-side installation.

  • Type-3 drivers are fully written in Java, hence they are portable drivers.
  • No client side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc.
  • Network support is required on client machine.
  • Maintenance of Network Protocol driver becomes costly because it requires database-specific coding to be done in the middle tier.
  • Switch facility to switch over from one database to another database.

Type-4 driver

Type-4 driver is also called native protocol driver. This driver interact directly with database. It does not require any native database library, that is why it is also known as Thin Driver.

  • Does not require any native library and Middleware server, so no client-side or server-side installation.
  • It is fully written in Java language, hence they are portable drivers.
Читайте также:  Как сделать кортеж python

Which Driver to use When?

  • If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is type-4.
  • If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.
  • Type 2 drivers are useful in situations, where a type 3 or type 4 driver is not available yet for your database.
  • The type 1 driver is not considered a deployment-level driver, and is typically used for development and testing purposes only.

This article is contributed by Sangeet Anand. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Источник

Оцените статью