JDBC-ODBC Integration


JDBC Overview

What is JDBC? In a nutshell, JDBC, which stands for Java Database Connectivity, is an API specification that defines the following.

  • How to interact with corporate data sources from Java applets, applications and servlets
  • How to use JDBC drivers
  • How to write JDBC drivers

The JDBC API is based on the X/Open CLI (Call-Level Interface), which defines how clients and servers interact with one another when using database systems. Microsoft's Open Database Connectivity (ODBC) is also based on the X/Open CLI, so it is considered a distant cousin. The JDBC specification follows a strict set of procedures and was officially released in June 1996 in the java.sql package.

The JDBC API is interoperable with databases due to the following the above specifications. What that means is that by using JDBC API for database access, you can change the underlying database driver (or engine) without having to modify your application.

JDBC-ODBC Bridge

As stated earlier, Microsoft's ODBC and Java's JDBC both share the X/Open CLI. Both APIs share the language they use, which is SQL. SQL used to be an acronym for Structured Query Language. SQL defines both how databases are defined and maintained with Data Definition Language (DDL) and how data are read and updated with Data Manipulation Language (DML). Since Microsoft is so saturated in the market, Java leveraged this fact and developed the JDBC-ODBC bridge.

The JDBC-ODBC bridge is a JDBC driver that uses native (C language) libraries that make calls to an existing ODBC driver to access a database engine. There are limitations to this.

  • The bridge was never intended to be a production piece of software, and it is not officially supported by JavaSoft.
  • The bridge uses native code, which has severe implications, being that the bridge has to be configured on a per machine basis. This goes against Java's "zero-install" model.
  • If there are bugs in the ODBC driver, there will be problems that cannot be avoided.
  • If your ODBC driver can't do it, neither can the bridge.

JDBC Driver Types

JavaSoft has defined four basic types of JDBC drivers.

  1. The JDBC-ODBC Bridge - As was discussed above, the bridge is part of the sun.jdbc.odbc package and is not required to be ported by vendors that provide a Java virtual machine.
  2. Java to Native API - This makes use of local native libraries provided by a vendor to communicate directly to the database.
  3. Java to Proprietary Network Protocol - This type of driver is the most flexible. It is typically used in a 3tier solution and can be deployed over the Internet.
  4. Java to Native Database Protocol - These drivers are pure Java drivers that communicate with the database engine via its native protocol

Our JDBC-ODBC Integration

In order for us to integrate JDBC into our program, we had to follow the basic JDBC flow. Those steps are to do the following...

  1. Establish a connection to the database
  2. Execute a SQL statement
  3. Process the results
  4. Disconnect from the database

Since we are connecting our Java application to a Microsoft Access database, we need to connect using the JDBC-ODBC bridge, execute a query against the database, display the results and perform the cleanup.

In order to use the JDBC-ODBC bridge and Microsoft Access, we first had to configure an ODBC data source. This was done using the ODBC Administration tool found in the Control Panel of Windows 95. We selected the Add button from the ODBC Administration. From the list of ODBC drivers we selected the Microsoft Access driver. At this point we entered the data source name, which is Alias. We also typed in a brief description of the data source. In the database field, we selected the location of where the database was stored on our web server. In this case, the database was stored in C:\Webshare\Wwwroot\xfer\alias.mdb. This database actually could have been stored anywhere, even on anther host. This part of the configuration was the most critical since it established the connection to the database.