Open In App

JDBC – Type 4 Driver

Let us do get a cover overview of the JDBC and the ODBC prior in order to better understand what exactly is type 4 driver. A JDBC driver enables Java application to interact with a database from where we can fetch or store data. JDBC drivers are analogous to ODBC drivers. The JDBC classes are contained in the Java Package java.sql and javax.sql.JDBC helps to 

The Java.sql package that ships with JDK, contains various classes with their behavior defined, and their actual implementations are done in third-party drivers. Third-party vendors implement the java.sql.Driver interface in their database driver.



ODBC is based on the device driver model, where the driver encapsulates the logic needed to convert a standard set of commands and functions into the specific calls required by the underlying system.



JDBC driver types are used to categorize the technology used to connect to the database.

  1. Type -1 Bridge driver
  2. Type -2 Native API
  3. Type -3 Network Protocol
  4. Type -4 Native Protocol

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

Type-4 JDBC driver also known as ‘thin driver’ or Direct to Database Pure Java Driver. It is portable, the fastest among all JDBC drivers and database dependent.

The thin driver converts JDBC calls directly into the vendor-specific database protocol. It is fully written in Java language. Also, it is a platform-independent driver but it is database dependent as it uses a native protocol(Protocol can establish a connection between particular server only).

Thin driver installs inside Java Virtual Machine of the Client.

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

Unicode supported

Multi-lingual applications can be developed on any operating system platform with JDBC using the Type 4 JDBC drivers to access both Unicode and non-Unicode enabled databases. Internally, Java applications use UTF-16 Unicode encoding for string data. When fetching data, the Type 4 JDBC drivers automatically perform the conversion from the character encoding used by the database to UTF-16. Similarly, when inserting or updating data in the database, the drivers automatically convert UTF-16 encoding to the character encoding used by the database.

Lets us do discuss the error handling in type 4 JDBC drivers as type 4 JDBC drivers are reported throwing errors to the calling application by throwing SQLExceptions. This is because each SQLException contains:

  1. Native error code
  2. Description of cause of the error
  3. A string containing the XOPEN SQLstate
Article Tags :