Java Reference
In-Depth Information
Fig. 7.6
Output from the
modifi ed
JDBC2Mods
program
7.12
Using the
DataSource
Interface
7.12.1
Overview and Support Software
As demonstrated in earlier sections of this chapter, the original method of accessing
remote databases via JDBC involves making use of the
DriverManager
class.
This is still the method used by many Java database programmers, but “the
preferred method” (as it is described on the Oracle site) is to make use of the
DataSource
interface. This interface is contained in package
javax.sql
and has been
part of the Standard Edition of Java since J2SE 1.4. The primary advantages of this
method are twofold, as detailed below.
1. The password and connection string are handled by a Web application server,
rather than being hard-coded into the application program. As a consequence,
security is greatly enhanced.
2. At the heart of the method is a concept called
connection pooling
(as described
briefl y in Sect.
7.2
). This is a much more effi cient method of handling multiple
database connections, and so is more applicable to real-world, commercial
databases.
Search WWH ::
Custom Search