Java Reference
In-Depth Information
JDBC originally only supported going to the next row in the result set, because this is the most basic functionality
that all supported datbaases provide. Currently many databases have a more advanced control structure, so more
advanced features are implemented in JDBC 2.1. ResultSets now support moving forward and backward
through the results, as well as relative and absolute positioning of the cursor. Also they have the option of being
updatable. This means that if you execute a query and then the underlying database changes, the result set
changes to reflect it.
The more advanced features like support for JNDI naming, Java Transaction Service (JTS) API, connection
pooling, and rowsets are in the optional package ( javax.sql ).
Pattern Use
The JDBC framework consists of many related objects that are only defined by their interfaces. This requires
static methods so that you can create instances of the implementing classes without knowing their actual class.
Abstract Factory (see page 6): Classes that implement the Connection interface use the Abstract Factory
pattern. The Abstract Factory provides flexibility. You can write an application without knowing what database
has been or will be chosen. You know the Connection interface, and you therefore know how to create
statements.
This benefit of flexibility also extends to runtime. The implementing class is determined at runtime, so the
application doesn't need to be changed just because another database or another driver has been chosen.
Factory Method (see page 21): It's easy to see that JDBC uses Factory Methods quite heavily. JDBC was
designed to be flexible so that developers could use the framework without knowing the implementing classes.
Therefore most of the JDBC API consists of interfaces. Because you can not call the constructor on an interface,
Factory Methods are used to create instances of the required type. This is the case with the getConnection
method in DriverManager . It instantiates an object that implements Connection and returns that object.
The Factory Methods provide a flexible way of creating objects without having to know their actual type.
Bridge (see page 150): The Bridge pattern underlies the whole JDBC API. JDBC provides a uniform interface
to multiple databases. It is this collection of interfaces that provides the decoupling of the implementation from
the client, the purpose of the Bridge pattern. The interfaces are the functional abstraction that separates out the
implementation.
The application that uses JDBC can change without affecting the implementation of a JDBC driver. The
driver—that is, the implementation of the JDBC interfaces—can change its internal workings, and the application
that uses the driver can remain unchanged.
Search WWH ::




Custom Search