«Back to Home

Core Java

Topics

JDBC Driver In Java

JDBC Driver
 
In Java, JDBC driver is a software component, which allows Java Application to interact with the database.
 
In other words, JDBC drivers implement the described interfaces in JDBC API to interact with our database Server.
 
When we use JDBC drivers, it allows us to open the database connections and to interact with it by sending SQL or the database commands, followed by receiving.
 
Java.sql package ships with JDK, which holds many classes with their behaviors described. Their actual implementations are done in third-party drivers and third party vendors implement java.sql.Driver interface in their database driver.
 
In Java, there are four kinds of JDBC drivers, which are,
  • JDBC-ODBC bridge driver

  • Native-API driver

  • Network Protocol driver

  • Thin driver

  1. JDBC-ODBC bridge driver

    In JDBC, JDBC-ODBC bridge driver uses ODBC driver to connect to the database. JDBC-ODBC bridge driver converts JDBC method calls into ODBC function calls.

    JDBC bridge is used to access ODBC drivers, installed on each client machine. Using ODBC needs configuring on our system a Data Source Name (DSN), which shows the target database.

    Previously, this was a very useful driver because most databases only supported ODBC access but now, this type of driver is suggested only for an experimental use or if no other alternative is available. This is now discouraged.

    Advantages of JDBC-ODBC bridge driver

    It can be easily used.

    It can be easily connected to any database.

    Disadvantages of JDBC-ODBC bridge driver

    Its performance degraded because JDBC method call is converted into ODBC function calls.

    It needs to be installed on the client machine.

    Let’s see the figure of JDBC-ODBC bridge driver, given below.

    20

  2. Native-API driver

    In JDBC, Native API driver uses the client-side libraries of the database. It converts JDBC method calls into native calls of the database API. It is not written fully in Java.

    In other words, JDBC API calls are converted into native C/C++ API calls, which are unique to the database. These drivers are typically provided by the database vendors and used in the same way as the JDBC-ODBC Bridge. The vendor-specific driver should be installed on each or every client machine. If we want to change the database, we have to change the native API, as it is specific to a database and they are mostly outdated now.

    Advantages of Native-API driver

    Its performance upgraded compared to JDBC-ODBC bridge driver.

    Disadvantages of Native-API driver

    It needs to be installed on the each client machine.

    The vendor client library needs to be installed on the client machine.

    Let’s see the figure of Native-API driver, given below.

    21

  3. Network Protocol driver

    In JDBC, Network Protocol driver uses middleware Application Server, which converts JDBC calls into the vendor-specific database protocol. It is fully written in Java.

    A three-tier approach is mainly used to access the databases. The clients of JDBC use standard network sockets to communicate with a middleware Application Server. The socket information is translated by the middleware Application Server into the call format, required by the DBMS and forwarded to the database Server. It is extremely flexible, as it requires no code, installed on the client and a single driver can actually provide an access to the multiple databases.

    Advantage of Network Protocol driver

    There is no client side library, which is required because of an Application Server, which can perform many tasks like auditing, load balancing etc.

    Disadvantages of Network Protocol driver

    Network support is required on the client machine.

    It requires a database-specific coding to be done in the middle tier.

    Maintenance of Network Protocol driver is costly because it requires database-specific coding to be done in the middle tier.

    Let’s see the figure of Network Protocol driver, given below.

    22

  4. Thin driver

    In JDBC, the thin driver converts JDBC calls the vendor-specific database protocol. Due to this, it is called a thin driver. It is fully written in Java language.

    A pure Java-based driver communicates directly with the vendor's database through socket connection. It is the highest performance driver, available for the database and it is usually provided by the vendor itself. It is extremely flexible. We don't need to install the special software on the client or the Server. Further, these drivers can be downloaded dynamically.

    Advantages of Thin driver

    It has a better performance than all other drivers.

    There is no software, which is required at the client side or Server side.

    Disadvantages of Thin driver

    A driver depends on the database.

    Let’s see the figure of thin driver, given below.

    23

Which Driver should be used?
  • When we are accessing one type of the database, such as Oracle, Sybase or IBM, the preferred driver type is thin driver.

  • When our Java Application is accessing multiple types of databases at the same time, Network Protocol driver is the preferred driver.

  • Native-API drivers are useful in situations, where a Network Protocol driver or type Thin driver is not available yet for our database.

  • JDBC-ODBC bridge driver is not considered a deployment-level driver and it is typically used only for the development and testing purposes.
Summary

Thus, we learnt, JDBC driver is a software component, which allows Java Application to interact with the database and also learn which driver should be used in Java.