2.6 Discuss Types of Drivers
-
JDBC drivers are divided
into four types or levels.
-
The different
types of jdbc drivers are:
1) Type 1: JDBC-ODBC Bridge driver (Bridge)
2) Type 2: Native-API/partly Java driver (Native)
3) Type 3: AllJava/Net-protocol driver
(Middleware)
4) Type 4: All Java/Native-protocol driver (Pure)
ü Type 1 JDBC Driver: (JDBC-ODBC Bridge driver :)
-
The
Type 1 driver translates all JDBC calls into ODBC calls.
-
And
sends them to the ODBC driver.
-
ODBC
is a generic API.
-
JDBC bridge is
used to access ODBC drivers installed on each client machine.
-
ODBC requires
configuring on wer system a Data Source Name (DSN).
-
That represents
the target database.
-
When Java first
came out, this was a useful driver.
-
Because most
databases only supported ODBC access.
-
The
JDBC-ODBC Bridge driver is recommended only for experimental use.
-
Or
when no other alternative is available.
-
JDBC-ODBC
bridge that comes with JDK 1.2 is a good example of this kind of driver.
[Fig. :
1 for JDBC-ODBC
bridge driver]
[Fig. :
2 for JDBC-ODBC
bridge driver]
Ø Advantage :
1)
The
JDBC-ODBC Bridge allows access to almost any database.
2)
Since
the database's ODBC drivers are already available.
Ø 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.
3)
They
are the slowest of all driver types.
4)
The
client system requires the ODBC Installation to use the driver.
5)
Not
good for the Web.
ü Type 2 JDBC Driver: (Native-API/partly Java driver:)
-
The
distinctive characteristic of type 2 jdbc drivers are that Type 2 drivers
convert JDBC calls into database-specific calls.
-
In a Type 2
driver, JDBC API calls are converted into native C/C++ API calls which are
unique to the database.
-
This
driver is specific to a particular database.
-
These drivers
typically provided by the database vendors.
-
Vendor-specific
driver must be installed on each client machine.
-
And used in the
same manner as the JDBC-ODBC Bridge.
-
Example: Oracle will have oracle native api.
-
If we change
the Database we have to change the native API as it is specific to a database.
-
And they are
mostly obsolete (out of date) now.
-
But we may
realize some speed increase with a Type 2 driver.
-
Because it
eliminates ODBC's overhead (cost).
-
Oracle Call
Interface (OCI) driver is an example of a Type 2 driver.
-
[Fig. :
1 for Native-API/Partly
Java Driver]
[Fig. :
2 for Native-API/Partly
Java Driver]
Ø Advantage :
1)
The
distinctive characteristic of type 2 jdbc drivers are that they are typically
offer better performance than the JDBC-ODBC Bridge.
2)
As
the layers of communication (tiers) are less than that of Type
1.
1.
3)
And
also it uses Native api which is Database specific..
Ø Disadvantages:
1)
Native
API must be installed in the Client System.
2)
and
hence type 2 drivers cannot be used for the Internet.
3)
Like
Type 1 drivers, it’s not written in Java Language which forms a portability
issue.
4)
If
we change the Database we have to change the native api as it is specific to a
database.
5)
Mostly
obsolete (out of date) now.
6)
Usually
not thread safe.
ü Type 3 JDBC Driver: (All Java/Net Protocol driver:)
-
Type
3 database requests are passed through the network to the middle-tier server.
-
The
middle-tier then translates the request to the database.
-
If
the middle-tier server can in turn use Type1, Type 2 or Type 4 drivers.
-
In a Type 3
driver, a three-tier approach is used to accessing databases.
-
The JDBC
clients use standard network sockets to communicate with an middleware
application server.
-
The socket
information is then translated by the middleware application server into the
call format required by the DBMS.
-
And forwarded
to the database server.
-
This kind of
driver is extremely flexible.
-
So, it requires no code installed on the client.
-
And a single
driver can actually provide access to multiple databases.
-
We can think of
the application server as a JDBC "proxy".
-
Meaning that it
makes calls for the client application.
-
As a result, we
need some knowledge of the application server's configuration.
-
In order to
effectively use this driver type.
-
Wer application
server might use a Type 1, 2, or 4 driver to communicate with the database
-
Understanding
the nuance (hint) will prove helpful.
[Fig. :
1 for All Java/Net -
Protocol Driver]
[Fig. :
2 for All Java/Net -
Protocol Driver]
Ø Advantage :
1)
This
driver is server-based.
2)
so
there is no need for any vendor database library to be present on client
machines..
3)
This
driver is fully written in Java and hence Portable..
4)
It
is suitable for the web.
5)
There
are many opportunities to optimize portability, performance, and scalability.
6)
The
net protocol can be designed to make the client JDBC driver very small and fast
to load.
7)
The
type 3 driver typically provides support for features such as caching
(connections, query results, and so on), load balancing, and advanced system
administration such as logging and auditing.
8)
This
driver is very flexible allows access to multiple databases using one driver.
9)
They
are the most efficient amongst all driver types.
Ø Disadvantages:
1)
It
requires another server application to install and maintain.
2)
Traversing
the recordset may take longer.
3)
Since
the data comes through the backend server.
ü Type 4 JDBC Driver: (All Java/Native Protocol driver:)
-
The
Type 4 uses java networking libraries to communicate directly with the database
server.
-
Type 4 driver,
a 100% pure Java-based driver that communicates directly with vendor's database
through socket connection.
-
This is the
highest performance driver available for the database
-
And is usually
provided by the vendor itself.
-
This kind of
driver is extremely flexible
-
We don't need
to install special software on the client or server.
-
These drivers
can be downloaded dynamically.
-
MySQL's
Connector/J driver is a Type 4 driver.
-
Because of the
proprietary (managing) nature of their network protocols, database vendors
usually supply type 4 drivers.
[Fig. :
1 for All Java/Native
- Protocol Driver]
[Fig. :
2 for All Java/Native
- Protocol Driver]
Ø Advantage :
1)
The
major benefit of using a type 4 jdbc drivers are that they are completely
written in Java to achieve platform independence.
2)
and
eliminate deployment administration issues.
3)
It
is most suitable for the web.
4)
Number
of translation layers is very less.
5)
Type
4 JDBC drivers don't have to translate database requests to ODBC.
i.
or
a native connectivity interface
ii.
or to pass the request on to another server,
6)
Performance
is typically quite good .
7)
We
don’t need to install special software on the client or server.
8)
These
drivers can be downloaded dynamically.
Ø Disadvantages:
1) With type 4
drivers, the user needs a different driver for each database.
Ø Which Driver should be used?
-
If we are
accessing one type of database, such as :
1) Oracle,
2) Sybase, or
3) IBM
-
Then preferred
driver type is 4.
-
If wer Java
application is accessing multiple types of databases at the same time, type 3
is the preferred driver.
-
Type 2 drivers
are useful in situations where a type 3 or type 4 driver is not available for wer
database.
-
The type 1
driver is not considered a deployment-level driver.
-
And is typically
used for development and testing purposes only.
No comments:
Post a Comment