Advanced Java (2160707)

BE | Semester-4   Winter-2018 | 20-11-2018

Q1) (c)

List different types of JDBC drivers and explain any two of them.

Types of JDBC Drivers

  • Type 1 (JDBC-ODBC Driver)
  • Type 2 (Native Code Driver)
  • Type 3 (Java Protocol)
  • Type 4 (Database Protocol)

Type 1 (JDBC-ODBC Driver)

  • Depends on support for ODBC
  • Not portable
  • Translate JDBC calls into ODBC calls and use Windows ODBC built in drivers
  • ODBC must be set up on every client
  • for server side servlets ODBC must be set up on web server driver sun.jdbc.odbc.JdbcOdbc provided by JavaSoft with JDK
  • No support from JDK 1.8 (Java 8)
  • E.g. MS Access
Type 1 (JDBC-ODBC Driver)
(Figure: Type 1 (JDBC-ODBC Driver))

Advantages

  • Allow to communicate with all database supported by ODBC driver
  • It is vendor independent driver

Disadvantages

  • Due to large number of translations, execution speed is decreased
  • Dependent on the ODBC driver
  • ODBC binary code or ODBC client library to be installed in every client machine
  • Uses java native interface to make ODBC call

Because of listed disadvantage, type1 driver is not used in production environment. It can only be used, when database doesn’t have any other JDBC driver implementation.


Type 2 (Native Code Driver)

  • JDBC API calls are converted into native API calls, which are unique to the database.
  • These drivers are typically provided by the database vendors and used in the same manner as the JDBC-ODBC Bridge.
  • Native code Driver are usually written in C, C++.
  • The vendor-specific driver must be installed on each client machine.
  • JDBC API calls are converted into native API calls, which are unique to the database.
  • These drivers are typically provided by the database vendors and used in the same manner as the JDBC-ODBC Bridge.
  • Native code Driver are usually written in C, C++.
  • The vendor-specific driver must be installed on each client machine.
  • Type 2 Driver is suitable to use with server side applications. E.g. Oracle OCI driver, Weblogic OCI driver, Type2 for Sybase
Type 2 (Native Code Driver)
(Figure: Type 2 (Native Code Driver))

Advantages

  • As there is no implementation of JDBC-ODBC bridge, it may be considerably faster than a Type 1 driver.

Disadvantages

  • The vendor client library needs to be installed on the client machine.
  • This driver is platform dependent.
  • This driver supports all java applications except applets.
  • It may increase cost of application, if it needs to run on different platform (since we may require buying the native libraries for all of the platform).

Type 3 (Java Protocol)

  • Pure Java Driver
  • Depends on Middleware server
  • Can interface to multiple databases – Not vendor specific.
  • Follows a three-tier communication approach.
  • The JDBC clients use standard network sockets to communicate with a middleware application server.
  • The socket information is then translated by the middleware application server into the call format required by the DBMS.
  • This kind of driver is extremely flexible, since it requires no code installed on the client and a single driver can actually provide access to multiple databases.
Type 3 (Java Protocol)
(Figure: Type 3 (Java Protocol))

Advantages

  • Since the communication between client and the middleware server is database independent, there is no need for the database vendor library on the client. A single driver can handle any database, provided the middleware supports it.
  • We can switch from one database to other without changing the client-side driver class, by just changing configurations of middleware server.
  • E.g.: IDS Driver, Weblogic RMI Driver

Disadvantages

  • Compared to Type 2 drivers, Type 3 drivers are slow due to increased number of network calls.
  • Requires database-specific coding to be done in the middle tier.
  • The middleware layer added may result in additional latency, but is typically overcome by using better middleware services.

Type 4 (Database Protocol)

  • It is known as the Direct to Database Pure Java Driver
  • Need to download a new driver for each database engine
  • e.g. Oracle, MySQL
  • Type 4 driver, a pure Java-based driver communicates directly with the vendor's database through socket connection.
  • This kind of driver is extremely flexible, you don't need to install special software on the client or server.
  • Such drivers are implemented by DBMS vendors.
Type 4 (Database Protocol)
(Figure: Type 4 (Database Protocol))

Advantages

  • Completely implemented in Java to achieve platform independence.
  • No native libraries are required to be installed in client machine.
  • These drivers don't translate the requests into an intermediary format (such as ODBC).
  • Secure to use since, it uses database server specific protocol.
  • The client application connects directly to the database server.
  • No translation or middleware layers are used, improving performance.
  • The JVM manages all the aspects of the application-to-database connection.

Disadvantage

  • This Driver uses database specific protocol and it is DBMS vendor dependent.