blogger templates blogger widgets
This is part of a list of blog posts.
To browse the contents go to

JDBC Driver and Driver Types

JDBC Drivers

What is a JDBC driver?

The JDBC API defines the Java interfaces and classes that programmers use to connect to databases and send queries. A JDBC driver implements these interfaces and classes for a particular DBMS vendor.

For eg:
Oracle releases JDBC drivers for it's famous Oracle Database. These drivers are available as jars that could be used by any java application.
To make it even more clearer,
If you check the JDBC API Docs we see that Driver is a interface but if we check Oracle Driver API Docs we find OracleDriver class that provides a implementation for Driver interface.

A Java program that uses the JDBC API loads the specified driver class Class.forName("oracle.jdbc.OracleDriver") for a particular DBMS (say, Oracle DB) before it actually connects to a database. The JDBC DriverManager class then sends all JDBC API calls to the loaded driver.



Driver Types

JDBC Drivers are divided into four types

• JDBC-ODBC bridge driver
• Native-API / partly Java Driver
• Net-protocol/ all java driver
• Native protocol/ all java driver

JDBC-ODBC bridge driver


- is a database driver implementation that employs the ODBC driver to connect to the database.
- The driver converts JDBC method calls into ODBC function calls.
- The driver is platform-dependent as it makes use of ODBC which in turn depends on native libraries of the underlying operating system the JVM is running upon.
- Almost any database for which ODBC driver is installed, can be accessed.
- Performance overhead since the calls have to go through the jdbc Overhead bridge to the ODBC driver, then to the native db connectivity interface
- Platform dependent
- The ODBC driver needs to be installed on the client machine.
- Not suitable for applets, because the ODBC driver needs to be installed on the client.

Example:
Sun provides a JDBC-ODBC Bridge driver: sun.jdbc.odbc.JdbcOdbcDriver.

Native-API / Partly Java driver


- is a database driver implementation that uses the client-side libraries of the database.
- As there is no implementation of jdbc-odbc bridge, its considerably faster than a type 1 driver.
- The vendor client library needs to be installed on the client machine.
- Not all databases have a client side library
- This driver is platform dependent
- This driver supports all java applications except Applets< Example: Oracle's OCI driver The JDBC OCI driver, written in a combination of Java and C, converts JDBC invocations to calls to OCI, using native methods to call C-entry points. These calls communicate with the database using SQL*Net.


Net-protocol / All Java driver


- also known as the Pure Java Driver for Database Middleware, is a database driver implementation which makes use of a middle tier between the calling program and the database.
- Like type 4 drivers, the type 3 driver is written entirely in Java
- Since the communication between client and the middleware server is database independent, there is no need for the database vendor library on the client
- The middleware server (which can be a full fledged J2EE Application server) can provide typical middleware services like caching (of connections, query results, etc.), load balancing, logging, and auditing.
- A single driver can handle any database, provided the middleware supports it.
- Requires database-specific coding to be done in the middle tier.

Example:
Oracle JDBC Server-Side Thin Driver - not strictly a type 3
driver runs inside Oracle Database and accesses a remote database or a different session on the same database.
This driver is useful in the following scenarios:
• Accessing a remote database server from an Oracle Database instance acting as a middle tier
• Accessing an Oracle Database session from inside another, such as from a Java stored procedure


Native-protocol / All Java driver


- is a database driver implementation that converts JDBC calls directly into a vendor-specific database protocol.
- Written completely in Java, type 4 drivers are thus platform independent. They install inside the Java Virtual Machine of the client.
- This provides better performance than the type 1 and type 2 drivers as it does not have the overhead of conversion of calls into ODBC or database API calls.
- Unlike the type 3 drivers, it does not need associated software to work.
- As the database protocol is vendor specific, the JDBC client requires separate drivers, usually vendor supplied, to connect to different types of databases.

Continue reading: Steps and Prerequisites for JDBC

1 comment:

  1. Mark Hurd Still that figures only takes in account the business of selling software services and tools to help companies build cloud-based apps, otherwise known as Software-as-a-Service and Platform-as-a-Service respectively. Hurd projected 80% of IT budgets will be spent on cloud service—not traditional IT systems that can only be used in a company’s internal data center…..

    ReplyDelete