Previous Table of Contents Next


Design Changes

In JDBC 2.0, the API has been split into two packages. The first package, java.sql, is referred to as JDBC 2.0 Core API. A new package, javax.sql, is called the JDBC 2.0 Standard Extension. The JDBC 2.0 Core API consists of all of the classes discussed in this chapter plus the list in Table 3.13.

Table 3.13 JDBC 2.0 Core API Class Additions

CLASS/INTERFACE USE

ArrayLocator An interface that represents reference during a transaction to an array of values in the database.

BatchUpdateException A subclass of SQLException that provides information on all statements within the batch being processed.

BlobLocator An interface that represents a reference to a binary large object in the database.

ClobLocator Similar to a BlobLocator except for Character Large Objects (CLObs).

Ref An interface that can be saved to persistent storage and represents a reference to a SQL structured value in the database.

SQLData A Java class registered for type mapping implements this interface. It enables the driver to populate the object with values from the database or write the class’s values to the database.

SQLInput Streams containing values that represent SQL values implement this interface.

SQLOutput Streams containing values that represent SQL values implement this interface.

SQLType This interface provides some information about a SQL type.

Struct Extends the SQLData interface for mapping of structured data.

StructLocator This interface represents a reference during a transaction to a structure in the database.

The javax.sql package contains the parts of the JDBC 2.0 API that are related to other Java standard extensions, such as the Java Naming and Directory Interface (JNDI) and the Java Transaction Service (JTS), discussed later in this book. This package includes features such as connection pooling and row sets. At the time of this writing, the specification was not available. For more information on javax.sql, check the Sun Web site at www.javasoft.com/products/jdbc/index.html.

Summary

JDBC provides a solid architecture for accessing a data source in a platform–independent fashion. Most significant is that JDBC leverages the benefits of the Java design philosophy by keeping the API simple and easy to use. As new drivers appear, they will continue to fall more and more into the level 3 and 4 categories, which means vendors of databases, application servers, and other middleware products will have a tendency to provide pure Java solutions. Drivers that will support JDBC 2.0 features will still work with your JDBC 1.0 applications. This means you should develop for JDBC today and think about how the JDBC 2.0 features will help you tomorrow.

When developing applications that access a database, the most critical issues are:

  Accessing the data and features of the specific data source
  Performance of the gateway used to access this database
  Ease of new features that can be added to the application for supporting advanced database calls
  Database resources should almost always be considered limited and valuable in your design

JDBC does a good job of providing a baseline API for accessing your data source and allowing driver suppliers to extend the API so you can access specific database features. However, if the driver you are using is limited, be prepared to make some database calls through other means, such as vendor–specific gateways or libraries. Just make sure you encapsulate these calls in a separate method or class so that as more advanced drivers come out, you can easily move all of your calls to JDBC–only solutions. JDBC–only solutions give you more flexibility and make future enhancements easier because the vendors will update the data access features for you. Most important, remember that connections to the database represent real network and database resources. You should disconnect as soon as possible or at least minimize the number of open connections a client holds, because most databases can only handle a limited number of these. One solution to this problem is to use an intermediate product such as an application server. These products can provide you with access to your database through shared connections to your database.

JDBC provides a standard API for Java developers and makes it possible to write database applications using a pure Java API. An enterprise developer can use JDBC to connect all its heterogeneous database systems. Many of the services provided by Sun enable Java programmers to access standard repositories of information. The next chapter looks at another type of data repository called a naming and directory service. A naming and directory service provides information about resources on the network, such as printer locations, employee e–mail address lookup, and so on. The name of the Java API for accessing these services is called the Java Naming and Directory Interface, or JNDI.

This chapter covered the basics of connecting to a database using JDBC 1.0. For a more comprehensive look at this topic, you may want to consider JDBC Database Access With Java: A Tutorial and Annotated Reference (Java Series) by Graham Hamilton, Rick Cattell, and Maydene Fisher, published by Addison–Wesley. Also check out the Sun Web site at www.javasoft.com/products/jdk/1.1/docs/guide/jdbc/getstart/introTOC.doc.html. If you are interested in taking a course on this topic, check www.pri.com for a Java course schedule.


Previous Table of Contents Next