Previous Table of Contents Next


CHAPTER 2
What Is JDBC?

Java Database Connectivity (JDBC) is an application programming interface (API) that describes a standard Java library for accessing data sources, primarily relational databases, that use the Structured Query Language (SQL). JDBC is JavaSoft’s answer to the corporate developer’s requirement for database access from an enterprise Java application. Not only does JDBC provide a standard API for accessing data sources such as relational databases, but it also provides a standard architecture for database vendors so they can provide data source drivers. These drivers allow access to the vendor’s products directly from your Java applications.


NOTE:  In May 1998, Sun released the JDBC 2.0 specification. The discussions in this book mostly refer to the JDBC 1.0 specification because few drivers support 2.0 at this time. Where appropriate, JDBC 2.0 features and enhancements are identified.

This chapter describes the goals and architecture of JDBC. It assumes you are familiar with relational database theory and SQL. If you are not familiar with SQL, you may want to read one of the many available SQL books such as A Visual Introduction to SQL by J. Harvey Trimble and David Chappell.

Although SQL is an ANSI standard language used to manage relational databases, each database vendor implements its own slightly unique version of SQL to take advantage of database-specific features. In order for application developers to access various databases without having to learn an entirely new database access library each time, standard specifications for database access drivers (sometimes referred to as bridges) have emerged. These standards allow developers to build applications that can access, view, and modify data from multiple, diverse databases as well as easily port new and existing applications to new data sources. The bridge acts as a translator that takes generic database access calls and translates them to database-specific calls. The most common driver specification is ODBC, or Open Database Connectivity. ODBC is a C- based standard developed by the SQL Access Group (SAG) standards committee and popularized by Microsoft. ODBC is based on the Call Level Interface (CLI) specification of SAG.


NOTE:  In 1995, SAG joined with the X/Open Data Management Technical Committee to form the X/Open SQL Access Group. This group is composed of representatives from AT&T, Inprise, Computer Associates, IBM, Informix, INTERSOLV, Microsoft Corporation, Oracle Corporation, Progress, Sybase, Visigenic Software, and other vendors.

ODBC allows users to access data in a relational database management system. ODBC provides a consistent interface for communicating with a database. However, the standard suffers from several drawbacks. Developers have complained that ODBC is slow and limited in functionality. Another problem is that ODBC drivers are platform specific. This means if you write your application to run on multiple platforms, you will need a separate driver for each platform, which makes your application less portable.


NOTE:  You can find more information on ODBC at www.microsoft.com/data/odbc/.

Like ODBC, JDBC uses drivers to create a bridge to a specific database. Because JDBC drivers are still being developed for many databases, you can use the JDBC/ODBC bridge from JavaSoft to act as your database driver until a native driver is available.


NOTE:  For a list of available JDBC drivers and vendors supplying them, check http://java.sun.com/products/jdbc/jdbc.drivers.html.

ODBC is more mature than JDBC, so there are drivers for accessing most databases through ODBC. The JDBC/ODBC bridge allows you to use a native Java interface to access your database through ODBC without having to learn the ODBC specification. This extra overhead does create some performance issues, and ODBC is not as rich a specification as JDBC; therefore you can’t take full advantage of all of JDBC’s capabilities with this driver. However, this technique will allow you to get up and running while the vendors continue to develop and deliver database-specific JDBC drivers. For most of the JDBC chapters in this book, we use the JDBC/ODBC bridge in our examples. It is free from JavaSoft and will work with most databases you may have access to, provided you have the appropriate ODBC driver.

Goals for JDBC

JDBC was modeled after the ODBC architecture. The JDBC developers had two high-level goals for its design: adhering to common database standards and keeping the API simple.

Support Common Database Standards

Java programmers use JDBC for most database access calls. The JDBC API is designed to allow application programmers to communicate with any data source that has a JDBC driver implementation. In order to talk to various data sources, the API must remain fairly generic. However, the goal is to replace the functionality of ODBC in C-based applications and specifically provide interaction with SQL databases. This goal is met in three ways:

JDBC provides the ability to pass raw SQL statements directly to the data source. By providing a facility for passing SQL to the database, JDBC allows the application programmer to take advantage of database-specific features. However, this means that the programmer has to be responsible for sending appropriate SQL commands. The drivers provide metadata that can indicate what commands are valid for a particular data source. Metadata is information about or documentation of other data managed within an application or environment. For example, meta-data in a relational database describes the database tables, including the name of each attribute, the type of each attribute, and the size of each attribute. JDBC provides methods to return this information from the driver.
JDBC drivers must at least support the ANSI SQL92 Entry Level standard in order to be considered compliant. Sun has trademarked the term “JDBC Compliant” in order to assure consumers that a vendor’s JDBC driver handles a minimum level of SQL support. Just because a driver does not have this stamp does not mean it is not a good driver. It simply indicates that the vendor chose not to conform to the SQL92 standard. In most cases, it is probably worth asking the vendor why it chose not to provide this minimum level of standard SQL support, because the industry expects this minimal level of interoperability.
JDBC architecture must support the functionality of common database bridges such as ODBC. JDBC developers realized it would take time for database vendors to provide native JDBC drivers for all the various data sources developers needed. They ensured that the JDBC API would provide a superset of the ODBC capabilities. JDBC improves on the ODBC standard and is optimized to leverage the strengths of the Java language. In general, Java programmers use JDBC for all database access calls. This way, creating one driver for ODBC, the JDBC/ODBC bridge, enables developers to immediately take advantage of JDBC with virtually any data source.

Supporting common standards enables enterprise developers to take advantage of the latest Java technologies while maintaining a high degree of interoperability with other industry-standard products. JDBC solves most relational database access requirements from Java.


Previous Table of Contents Next