Pick a Free OS

User login

Navigation

An Introduction to JDBC

Email: 

Manu Konchady

Mitre Corporation,

1820 Dolley Madison Blvd., M/S W431,

McLean, VA 22102.

In 1996, Sun released a version of the Java Database Connectivity

(JDBC) kit. This package allowed programmers to use Java to connect,

query, and update a database using the Structured Query Language

(SQL). The use of Java with JDBC has advantages over other database

programming environments. Programs developed with Java and JDBC are

platform and vendor independent, i.e. the same Java program can run on

a PC, a workstation, or a network computer. The database can be

transferred from one vendor to another and the same Java programs can

be used without alteration. This article will discuss how JDBC can be

used with the Mysql database (see the September, October, and November

1997 issues of At the Forge ). Some of the benefits of using Java over

CGI will be exposed and the basics to manage a departmental database

with Java will be covered. A number of technologies have been

developed for databases such as transaction processing, triggers, and

indexes which are supported by JDBC. However, these topics are beyond

the scope of this article. Since the JDBC package is relatively new,

there are few tools available that database developers expect such as

report generators, query builders, and form designers. In the near

future, more tools should be available. Despite the lack of tools, it

is possible to develop highly interactive web pages using the JDBC API

without much complexity.

Design:

The idea behind JDBC is similar to Microsoft's Open Database

Connectivity (ODBC). Both ODBC and JDBC are based on the X/Open

standard for database connectivity. Programs written using the JDBC

API communicate with a JDBC driver manager, which uses the current

driver loaded. There are two architectures to communicate with the

database (Fig. 1). In the first architecture, the JDBC driver

communicates directly with the database. The driver connects to the

database and executes SQL statements on behalf of the Java program.

Results are sent back from the driver to the driver manager and

finally to the application. In the second architecture, the JDBC

driver communicates with an ODBC driver via a "bridge". A single JDBC