DataDirect Technologies - What is JDBC


What Is JDBC?

JDBC™ is an API developed by Sun Microsystems that provides a standard way to access data using the Java™ programming language. Using JDBC, an application can access a variety of databases and run on any platform with a Java Virtual Machine. It isn't necessary to write separate applications to access different database systems (Oracle and Sybase, for example). Using JDBC allows you to write one application that can send SQL statements to different database systems. SQL is the standard language for accessing relational databases.

The JDBC API defines a set of Java interfaces that encapsulate major database functionality, such as running queries, processing results, and determining configuration information. Because JDBC applications are written in Java, applications work on any platform.

How Does JDBC Work?

Simply, JDBC makes it possible to do the following things within a Java application:

  • Establish a connection with a data source
  • Send queries and update statements to the data source
  • Process the results

The following figure shows the components of the JDBC model.

The Java application calls JDBC classes and interfaces to submit SQL statements and retrieve results.

The JDBC API is implemented through the JDBC driver. The JDBC Driver is a set of classes that implement the JDBC interfaces to process JDBC calls and return result sets to a Java application. The database (or data store) stores the data retrieved by the application using the JDBC Driver.

The main objects of the JDBC API include:

  • A DataSource object is used to establish connections. Although the Driver Manager can also be used to establish a connection, connecting through a DataSource object is the preferred method.
  • A Connection object controls the connection to the database. An application can alter the behavior of a connection by invoking the methods associated with this object. An application uses the connection object to create statements.
  • Statement, PreparedStatement, and CallableStatement objects are used for executing SQL statements. A PreparedStatement object is used when an application plans to reuse a statement multiple times. The application prepares the SQL it plans to use. Once prepared, the application can specify values for parameters in the prepared SQL statement. The statement can be executed multiple times with different parameter values specified for each execution. A CallableStatement is used to call stored procedures that return values. The CallableStatement has methods for retrieving the return values of the stored procedure.
  • A ResultSet object contains the results of a query. A ResultSet is returned to an application when a SQL query is executed by a statement object. The ResultSet object provides methods for iterating through the results of the query.

For an excellent introduction to JDBC, take a look at Chapter 2 of "Java Enterprise in a Nutshell - An Introduction to JDBC" by Jim Farley, William Crawford, and David Flanagan (Second Edition April 2002) available online here.

Why Do We Need JDBC?

Why can't application developers use ODBC (Open Database Connectivity) on the Java platform? After all, it's an established standard API for database access. You can use ODBC; however, ODBC isn't appropriate for direct use from the Java programming language because it uses a C interface. The JDBC API was modeled after ODBC, but, because JDBC is a Java API, it offers a natural Java interface for working with SQL. JDBC is needed to provide a "pure Java" solution for application development.

Types of JDBC Drivers

Today, there are four types of JDBC drivers in use:

  • Type 1: JDBC-ODBC bridge
  • Type 2: partial Java driver
  • Type 3: pure Java driver for database middleware
  • Type 4: pure Java driver for direct-to-database

For most applications, the best choice is a pure Java driver, either Type 3 or Type 4. Type 4 drivers (such as DataDirect Connect for JDBC drivers) are the most common and are designed for a particular vendor's database. In contrast, a Type 3 driver is a single JDBC driver used to access a middleware server, which, in turn, makes the relevant calls to the database. A good example of Type 3 JDBC driver is the DataDirect SequeLink for JDBC driver. Type 1 drivers are used for testing JDBC applications against an ODBC data source. Type 2 drivers require a native database API to be used. Both Type 1 and Type 2 mix a Java-based API with another API.

The following figure shows a side-by-side comparison of the implementation of each JDBC driver type. All four implementations show a Java application or applet using the JDBC API to communicate through the JDBC Driver Manager with a specific JDBC driver.

See the JDBC Overview page on the Sun Microsystems web site for details about the four types of JDBC drivers.

What's the Difference Between DataDirect's Implementation of JDBC and Other Alternatives?

DataDirect Technologies' JDBC drivers provide the following advantages over other JDBC drivers:

  • The only Type 4, database-independent JDBC driver for all major databases - Oracle, DB2, Microsoft SQL Server, Sybase, and Informix.
  • 100% database-independent - no vendor-specific proprietary extensions.
  • The only Type 4 JDBC driver that supports Windows authentication for Microsoft SQL Server with an implementation that does not require loading external shared libraries (DLLs on Windows); DataDirect has a patent pending on this new exciting technology.
  • The only JDBC driver to offer distributed transaction support across all major databases.
  • Includes a JDBC Software Developer's Kit (SDK) that provides tools for troubleshooting and debugging your JDBC applications.
  • Certified under Sun Microsystems' J2EE Compatibility Test Suite (CTS).
  • Best performance and scalability in the market as measured by SPECjAppServer2002.
  • Award-winning 24x7 technical support to ensure rapid response to customer concerns (see the SupportLink website for more information).
  • DataDirect Technologies works closely with Oracle, IBM, Microsoft, Sybase, and other database vendors. This allows DataDirect Technologies early access to new database versions, insight into product and architectural direction, and to be the first to market with support for new database releases.

Which Version of the JDBC Specification Does DataDirect Technologies Support?

DataDirect Technologies' JDBC products support the current version of the JDBC specification, JDBC 3.0. You can download the JDBC 3.0 specification from the Sun Microsystems website. DataDirect Technologies also is the only third-party data connectivity vendor to sit on the JDBC Expert Panel, the group that defines the future of the JDBC specification. DataDirect has plans to support the JDBC 4.0 specification in the future. Proposals for the 4.0 specification are now available.

What Features of JDBC 3.0 Are Most Important?

Following are some of the features that are part of the JDBC 3.0 specification:

  • Retrieval of auto-generated keys
  • Blob/Clob Updates
  • Multiple open result sets
  • Transactional Savepoints
  • Statement Pooling

For an explanation of these and other JDBC 3.0 features, see Important Features in JDBC 3.0.

JDBC Performance

See Designing Performance-Optimized JDBC Applications for guidelines that will help you improve your JDBC application performance, including information about:

  • Using DatabaseMetaData methods appropriately
  • Retrieving only required data
  • Selecting functions that optimize performance
  • Managing connections and updates

JDBC Diagnostics

The JDBC API lets you see warnings and exceptions generated by the database and by the JDBC driver. A SQLException object contains a description of the error, the X/Open SQLState, and the driver vendor's error code number. To see exceptions, you can use a catch block to print them.

Warnings are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application; they simply alert the user that something did not happen as planned, such as a privilege that was not revoked as requested. Warnings can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), and a ResultSet object. Warnings can be retrieved on these objects using the getWarnings method.

DataDirect Technologies makes it easy to debug and troubleshoot your JDBC applications by offering a JDBC Software Developer's Kit (SDK) that provides the following tools:

  • DataDirect Test for JDBC is a graphical, menu-driven component that helps developers debug JDBC applications. It works by displaying the results of all JDBC function calls with sample Java JDBC code (including comments). DataDirect Test makes troubleshooting easy, shortening the application development cycle.
  • DataDirect Spy for JDBC traces JDBC calls in running applications. This utility passes calls issued by an application to the underlying DataDirect Technologies' JDBC driver and logs detailed information about those calls. The results passed back from the database to the application are also logged. DataDirect Spy differs from DataDirect Test in that DataDirect Spy is used with running applications to trace the JDBC calls made by that application, while DataDirect Test allows a developer to test their applications and experiment with the JDBC API during development.

These tools are only available with DataDirect Technologies' JDBC drivers.

Important Features of DataDirect Technologies' JDBC Drivers

General - All Drivers

  • DataDirect has a long-standing strategic technology relationship with Sun Microsystems. We helped to build the JDBC standard and continue to be involved in its evolution.
  • Four out of five of the major application server vendors embed DataDirect JDBC drivers in their application server products.
  • DataDirect Technologies is the only third-party data connectivity vendor to sit on the JDBC Expert Panel, the group that defines the future of the JDBC specification.
  • JDBC 3.0-compliant, providing comprehensive support for JDBC 3.0 features, including transactional savepoints, Blob/Clob updates, and the retrieval of auto-generated keys.
  • DataDirect is the only third-party data connectivity vendor to be a J2EE licensee.
  • DataDirect is committed to quality that is assured by rigorous product testing and uses the largest in-house JDBC test suite in the industry.
  • DataDirect offers award-winning 24x7 technical support.

DB2

  • Only Type 4 JDBC solution that supports all major versions of DB2 using a single driver.
  • Only JDBC driver to offer distributed transaction support across all major databases, including DB2.
  • High performance with more concurrent users than any other DB2 driver in the market as measured by the SPECjAppServer2002 and ECPerf benchmarks.
  • J2EE compatible, certified under Sun Microsystems' J2EE Compatibility Test Suite (CTS).
  • Utilizes the batch functionality provided by DB2 when performing batch operations, which reduces expensive network roundtrips between the JDBC driver and the database.
  • Provides seamless use of DB2 SQL batch commands.
  • Works with any Java Runtime of 1.2 or higher.

Informix

  • Only Type 4 JDBC solution that supports all major versions of Informix using a single driver.
  • Only JDBC driver to offer distributed transaction support across all major databases, including Informix.
  • Supports extended functionality for high-end applications, including support for all scrollable cursor types, unrestricted updateable result sets, savepoints, prepared statement pooling, and multiple open result sets.
  • Clear performance winner for read-intensive applications.
  • Supports sensitive scrollable result sets, as well as insensitive and forward only result sets.
  • Supports the BLOB and CLOB data types fully and reliably.
  • Supports the ability to return multiple result sets from a stored procedure.

Oracle

  • Only Type 4 JDBC solution that supports all major versions of Oracle using a single driver.
  • Only JDBC driver to offer distributed transaction support across all major databases, including Oracle.
  • Clear performance winner for most applications, especially those that use stored procedures, batch queries, bulk loading of data, and are network-intensive.
  • SPECjAppServer2002 leader in scalability.
  • Fastest Oracle driver in the market when retrieving results from SELECT statements.
  • J2EE compatible, certified under Sun Microsystems' J2EE Compatibility Test Suite (CTS).
  • Exposes Oracle features inside the JDBC standard and not through proprietary extensions.

SQL Server

  • Only Type 4 JDBC solution that supports all major versions of SQL Server using a single driver.
  • Only JDBC driver to offer distributed transaction support across all major databases, including SQL Server.
  • Only Type 4 JDBC driver that supports Windows authentication for Microsoft SQL Server with an implementation that does not require loading external shared libraries (DLLs on Windows); DataDirect has a patent pending on this new exciting technology.
  • Clear performance winner for most applications, especially those that use connection pooling and batch query optimizations.
  • J2EE compatible, certified under Sun Microsystems' J2EE Compatibility Test Suite (CTS).
  • Reliable - it was built in conjunction with the Microsoft SQL Server development team and was not reverse engineered.
  • Provides extended functionality support for world-wide organizations - all SQL Server internationalization features are exposed in an unrestricted manner.
  • SPECjAppServer2002 leader in scalability.
  • Fully supports connecting to named instances of SQL Server.

Sybase

  • Only Type 4 JDBC solution that supports all major versions of Sybase using a single driver.
  • Only JDBC driver to offer distributed transaction support across all major databases, including Sybase.
  • Provides extended functionality for high-end applications by supporting all scrollable cursors types, unrestricted updateable result sets, LOB interfaces, savepoints, prepared statement pooling, and multiple open result sets.
  • Clear performance winner for most applications, especially those that use bulk operations, batch queries, and stored procedure arrays.
  • J2EE compatible, certified under Sun Microsystems' J2EE Certification Test Suite (CTS).

Copyright © 1993 - 2008. Progress Software Corporation. All rights reserved. | N. America: 800 876 3101 | World: +44 (0) 1753 218 930