Java Reference
In-Depth Information
H OW JDBC W ORKS
Most business applications today need to store information in relational databases.
Business applications written in Java are no exception. The standard Java database
access technology is JDBC. JDBC is essentially a variation on ODBC with some Java
bindings. It is designed as a Java API to Structured Query Language (SQL) data.
JDBC is just a specification; it is up to the various database vendors or third
parties to create JDBC drivers for a particular database. In some cases, a JDBC-
ODBC bridge can be used, but likely not for production purposes.
JDBC provides a fairly complete set of SQL-friendly data access mechanisms,
such as scrollable result sets, absolute and relative positioning (in the result set), ac-
cess to stored procedures, and data type conversions. Most SQL-92 (Entry Level 2)
statements are supported in JDBC.
In order to access relational databases through Java and JDBC, we need a JDBC
driver that can perform whatever communications and translations are required to
act upon the database. A driver is a set of Java classes (usually in the form of a jar
file) provided by the vendor that adopts the standard behaviors required for all
JDBC drivers. These standard behaviors are defined in the various Java interfaces
that comprise the JDBC API. The API, in addition, defines certain optional behav-
iors that a driver may choose to support. The API provides the ability to query the
capabilities of the driver once it is loaded.
How the driver goes about its business behind the scenes is completely up to
the driver. JDBC drivers may communicate from Java to native code, which then
communicates with the database.
Other drivers use Java to communicate with the database using middleware or
through direct communication with the database. These do not require that any na-
tive code be installed on the client machine.
Type 1 and Type 2 JDBC drivers fall into the first group of drivers. They require
native code on the client machine. A Type 1 driver is a JDBC-ODBC bridge. It
translates the JDBC calls into ODBC calls and uses ODBC to access the database. A
Type 2 driver converts JDBC calls into the native API for the database. This requires
that binary code from the database vendor be installed and configured properly on
the client.
Type 3 and Type 4 JDBC drivers fall into the second group of drivers. They do
not require native code on the client machine. They require only the Java packages
and classes that support the driver. A Type 3 JDBC driver relies on a middleware
server to handle its communications with the database. A Type 4 JDBC driver com-
municates directly with the database from Java without any intermediary software
other than the communication protocol itself. Figure 13.1 illustrates how JDBC
works with the various driver types.
Search WWH ::




Custom Search