Java Database Connectivity

by Dinesh 2012-07-23 11:43:50

Java Database Connectivity (JDBC)


The JDBC specification and its reference implementation classes are Sun products. Like other specifications such as those included in the Sun Web Services Developer Pack (JAXP, JAXB, JAXM, and so on), the JDBC specification is part of the Java Community Process (JCP). At the time of this writing, the latest version of JDBC is the JDBC 3.0 API. JDBC containsclasses that are stored in the java.sql and javax.sql packages. Java’s JDK 1.4 and up bundle JDBC as part of the JDK, so no additional packages are needed. Otherwise, you’ll have to download JDBC support from http://java.sun.com/ products/jdbc/download.html and follow the instructions for setting up the packages to use the examples in this chapter.

JDBC supports reading and writing of data from Java to external data sources. Even though JDBC is a Sun product, it’s based on the X/Open SQL call level interface (CLI) specification, which is the same specification that Microsoft’s Open Database Connectivity (ODBC) offerings are based on. Because of this, JDBC and ODBC functionality is closely related, and some JDBC drivers use ODBC as their connection service. More information on the X/Open SQL CLI can be found at http://www. opengroup.org.

JDBC is based on the java.sql and javax.sql packages for JDBC support coding access to a JDBC driver. JDBC drivers are not included in the JDK or the JDBC downloads. Most relational database vendors have created JDBC drivers for their database offerings. Aside from vendor-provided drivers, there are dozens of thirdparty JDBC drivers. Sun hosts a page that lists JDBC drivers and vendors at http://industry.java.sun.com/products/jdbc/drivers.

Besides the three JDBC specification versions, there are four types of JDBC drivers:

  • Type 1 JDBC drivers function as a JDBC-ODBC bridge. Just like a real bridge, Type 1 drivers connect two things together. On one side, a Java interface is used to map a connection to an ODBC driver. The ODBC driver does all of the work of connecting to the database, and feeding information between the relational data source and the Java interface on the other side of the bridge.

  • Type 2 drivers rely on external code to function. That code may be written in Java or any other language, as long as it provides access to the driver through Java.

  • Type 3 drivers are written completely in Java. They can be downloaded and configured at runtime, and talk to relational databases and middleware servers via custom protocols.

  • Type 4 drivers are Java-like Type 3 drivers. They handle connections directly to database servers without any conversion protocols between the server and the RDBMS.

The Microsoft SQL Server, Oracle, and DB2 (via the IBM DB2 Connect product) all provide JDBC 3 Type 4 drivers with their RDBMS products. Even though all JDBC drivers claim to fully support JDBC specifications, we’ve found that each provider had interpreted the JDBC specifications in different ways. This means that while there are significant compatibilities between provided JDBC drivers, you will find that there are differences in functionality. The promise of being able to access any database using the same J2EE code by swapping out one JDBC driver for another is a good one, but not quite there yet.
927
like
0
dislike
0
mail
flag

You must LOGIN to add comments