ajp chp 5
ajp chp 5
• Disadvantages
1. Since the Bridge driver is not written fully in Java,
Type 1 drivers are not portable.
2. A performance issue is seen as a JDBC call goes
through the bridge to the ODBC driver, then to the
database, and this applies even in the reverse
process. They are the slowest of all driver types.
3. The client system requires the ODBC Installation
to use the driver.
4. Not good for the Web.
Type 2 JDBC Driver
Native-API/partly Java driver
• Type 2 drivers convert JDBC calls into (native C/C++
API calls) database-specific calls i.e. this driver is
specific to a particular database.
• Example: Oracle will have oracle native API.
• Advantage
Offer better performance than the JDBC-ODBC
Bridge as the layers of communication (tiers) are
less than that of Type 1 and also it uses Native API
which is Database specific.
• Disadvantage
1. Native API must be installed in the Client System
and hence type 2 drivers cannot be used for the
Internet.
2. Like Type 1 drivers, it’s not written in Java
Language which forms a portability issue.
3. If we change the Database we have to change
the native API as it is specific to a database
Type 3 JDBC Driver
Network-Protocol driver/All Java
• Type 3 database requests are passed through the
network to the middle-tier server (application server)
• Middle tier server converts JDBC calls directly or
indirectly into the vendor-specific database protocol.
• Here all the database connectivity drivers are present
in a single server, hence no need of individual client
side installation
• Advantage
1. This driver is server-based, so there is no need for
any vendor database library to be present on client
machines.
2. This driver is fully written in Java and hence Portable.
It is suitable for the web.
3. The net protocol can be designed to make the client
JDBC driver very small and fast to load.
4. This driver is very flexible allows access to multiple
databases using one driver.
5. They are the most efficient amongst all driver types.
• Disadvantage
It requires another server application to install and
maintain. Traversing the recordset may take longer,
since the data comes through the backend server.
Type 4 JDBC Driver
Native-Protocol/Database Protocol/All-Java driver
• The Type 4 uses java networking libraries to
communicate directly with the database server.
• This driver converts JDBC calls directly into the
vendor-specific database protocol, it does not require
any native database library, that is why it is known as
thin driver.
• It is fully written in Java language.
• Advantage
1. This type of drivers are completely written in Java so it
achieves platform independence and eliminate
deployment administration issues. It is most suitable
for the web.
2. Number of translation layers is very less i.e. type 4
JDBC drivers don't have to translate database requests
to ODBC or a native connectivity interface or to pass
the request on to another server, so performance is
also good.
3. No need to install special software on the client or
server.
4. These drivers can be downloaded dynamically.
• Disadvantage
With type 4 drivers, the user needs a different driver for
each database.
Which driver should be used ?
• If you are accessing one type of database,
such as Oracle, Sybase or IBM the preferred
driver type is 4.
• If your java application is accessing multiple
types of database at the same time, type 3 is
the preferred driver.
• Type 2 drivers are useful in situations, where
type 3 or type 4 driver is not available.
• Type 1 driver is not considered a deployment
level driver, and is typically used for
development and testing purpose only.
DriverManager class
• It acts as an interface between user and
drivers.
• It keeps track of the drivers that are
available and handles establishing a
connection between a database and the
appropriate driver.
• It also maintains a list of Driver classes that
have registered themselves by calling the
method DriverManager.registerDriver().
Commonly used methods of
DriverManager class:
1) public static void registerDriver It is used to register the given
(Driver driver): driver with DriverManager.