Sie sind auf Seite 1von 23

Different Types of JDBC Drivers

Connect with Databases

Chi-Hua Chen 9634501, Chang-Min Chen 9634508, Yin-Lung Lu 9634528


Ming-Chia Li 9634519, Hsin-Ying Hsieh 9634512, Ying-Yu Lin 9634509, Chia-Wei Hsu 9634524
Institute of Information Management,
National Chiao Tung University, Hsinchu, Taiwan.
Content
Content .................................................................................................................... 1
1 Introduction ..................................................................................................... 3
1.1 JDBC API Environment............................................................................ 4
1.2 Drivers Type............................................................................................... 4
2 Objective .......................................................................................................... 7
3 Hardware & Software Environment............................................................... 7
3.1 Hardware ................................................................................................... 7
3.2 Software...................................................................................................... 7
4 Approach(Design) ............................................................................................ 7
5 Development sample...................................................................................... 12
6 Results (Execution) ........................................................................................ 13
6.1 Processing time......................................................................................... 13
6.2 Through-put and packet size ................................................................... 17
7 Alternatives.................................................................................................... 22
7.1 JDO........................................................................................................... 22
7.2 Hibernate.................................................................................................. 22
8 Discussion and Conclusion ............................................................................ 22
9 Reference........................................................................................................ 23

2
1 Introduction
Java DataBase Connectivity〈JDBC〉, a Java API that enables Java programs
to execute SQL statements. This allows Java programs to interact with any
SQL-compliant database. Since nearly all relational database management
systems (DBMSs) support SQL, and because Java itself runs on most platforms,
JDBC makes it possible to write a single database application that can run on
different platforms and interact with different DBMSs.
In the past the database API interfaces are inconsistent, then if programmers
want to use database of A-manufacturer, we have to design an appropriate
program to manipulate the API and that is different from the database of
B-manufacturer, even if the same purpose of upper application of program.
Therefore, the JDBC API concept had been proposed.
Simply, JDBC technology allows the programmers to use the Java
programming language to exploit "Write Once, Run Anywhere" capabilities for
applications that require access to enterprise data. JDBC is similar to ODBC, but
is designed specifically for Java programs, whereas ODBC is
language-independent.

The JDBC architecture is shown in Figure 1.

Figure1. JDBC architecture

3
1.1 JDBC API Environment
The four sections of JDBC architecture are application, JDBC function
library, JDBC driver manager, and JDBC driver. Any Java program has to
implement on JVM (Java Virtual Machine). For the purpose of connecting
database, we have to install JDBC function library on Java platform, is
so-called JDBC API. JDBC API defines variable database object, including
database connection, data type process, SQL command, return values,
exception handling and so on. Nevertheless, it is just an abstract interface. The
real implementation is JDBC driver, who connects databases, operates data
and returns value.

1.2 Drivers Type


JDBC Drivers are client-side adaptors (they are installed on the client
machine, not on the server) that convert requests from Java programs to a
protocol that the DBMS can understand.
There are commercial and free drivers available for most relational
database servers. These drivers fall into one of the following types:

 Type1: the JDBC-ODBC bridge


The type 1 driver,
JDBC-ODBC Bridge, translates
all JDBC calls into ODBC (Open
DataBase Connectivity) calls and
sends them to the ODBC driver.
As such, the ODBC driver, as
well as, in many cases, the client
database code, must be present on
the client machine. Figure 2
shows a typical JDBC-ODBC
Bridge environment.

Figure2. Type 1 driver

4
 Type2: the Native-API driver
JDBC driver type 2 -- the
native-API/partly Java driver --
converts JDBC calls into
database-specific calls for databases
such as SQL Server, Informix, Oracle,
or Sybase. The type 2 driver
communicates directly with the
database server; therefore it requires
that some binary code be present on
the client machine. Figure 3 shows a
typical native-API/partly Java driver
environment.

Figure3. Type 2 driver

 Type3: the network-protocol driver


JDBC driver type 3 -- the
net-protocol/all-Java driver, also known Calling Java Application

as the Pure Java Driver for Database JDBC API


Middleware -- follows a three-tiered
JDBC Driver Manager
approach whereby the JDBC database
requests are passed through the
Network-Protocol Driver
network to the middle-tier server. The [Pure Java JDBC Driver]
(Type 3 Driver)
middle-tier server then translates the
request (directly or indirectly) to the
database-specific native-connectivity
interface to further the request to the Middleware
(Application Server)
database server. If the middle-tier
server is written in Java, it can use a
type 1 or type 2 JDBC driver to do this.
Database Database
Database
Figure 4 shows a typical
network-protocol driver environment. Different database vendors

Figure4. Type 3 driver

5
 Type4: the native-protocol drivers
The native-protocol/all-Java driver,
Calling Java Application
also known as the Direct to Database
Pure Java Driver (JDBC driver type 4) JDBC API

converts JDBC calls into the JDBC Driver Manager

vendor-specific database management


system (DBMS) protocol so that client Native-Protocol Driver
[Pure Java Driver]
applications can communicate directly (Type 4 Driver)
with the database server. Level 4 drivers
are completely implemented in Java to
Direct calls using
achieve platform independence and specific database protocol

eliminate deployment administration


issues. Figure 5 shows a typical
native-protocol/all-Java driver Database

environment.
Figure5. Type 4 driver

There is a comparison of JDBC driver types below in the Table 1.

Table 1. comparison of JDBC driver types


Driver Type Type 1 Type 2 Type 3 Type 4
Suitable Standalone Standalone Distributed Standalone
Environment Remote DB Remote DB architecture Remote DB
Efficiency Low High Middle High
Connection Low High/Middle High Middle
load capacity
Flexible High
Number of Few Few Normal Many
drivers
Cross-platform Yes Yes
Compatibility Low Middle High High

6
2 Objective
Using JDBC technology to design a example application to describe the
development process for creating distributed, object-based applications for Java.
Learn the process of middleware development, and understand the JDBC
infrastructure and how it works. Here, for many hetero-databases, we could
choice the method of the JDBC connections from different driver types that you
want through the single JDBC application programming interface.

3 Hardware & Software Environment


3.1 Hardware
AMD Semprom(tm) 1.00 GHz
512 MB RAM, Physical Address Extension

3.2 Software
Windows XP Professional Version 2002, Service Pack 2
Java Runtime Environment 1.5.0 (J2SE)
MySQL database 5.0.22
Oracle database 10g

4 Approach(Design)
This project is to create a simple program that performs the connections of
the different database to compare the different drivers’ performance, and the
package flow. First, it has to install databases, that we use the Oracle 10g and
MySQL. On the bridge aspect, for MySQL, it has to download ODBC driver and
set up JDBC data source, and then connects it by using the build-in ODBC-JDBC
Bridge (see Figure 6-1 to Figure 6-3 below). We can download ODBC Driver
from the website: http://dev.mysql.com/downloads/connector/odbc/3.51.html

7
Figure 6-1

Figure 6-2

8
Figure 6-3
For Oracle, we need not download other software because Window already has
build-in ODBC driver for Oracle. As long as the well setting of the ODBC data source,
and then connects it by using Sun JDBC-ODBC Bridge (see Figure 7 below).

Figure 7-1

9
Figure 7-2

Figure 7-3

10
Figuer 7-4
On the driver aspect, except that the official drivers of Oracle and MySQL
could be downloaded from their website respectively, the Oracle 10g i-net gate3
Driver could be found from http://www.inetsoftware.de/Download.htm and
download the i-net Oranxo that we used.
In addition, we use the Connection Pool mechanism to promote the
efficiency and facility. In our case, we use DBCP of the jakata project to
development Connection Pool mechanism that could be used everywhere. To
add this function on the project, we have to download Collections, DBCP, and
Pool components from the website: http://commons.apache.org/index.html.
The following lists the webs that could download other components:

Mysql db (phpmyadmin + mysql + apache server):


http://www.appservnetwork.com/?modules=&applang=tw

J2sdk 1.5:
http://java.sun.com/javase/downloads/?intcmp=1281

Tomcat jsp container:

11
http://tomcat.apache.org/download-55.cgi

Oracle 10g:
http://www.oracle.com/technology/software/products/database/index.html

Jdbc-odbc bridge: built-in Jdk

MySql odbc: http://dev.mysql.com/downloads/connector/odbc/3.51.html

Mysql official jdbc driver:


http://www.mysql.com/products/connector/j/

Oracle official jdbc driver:


http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

third-party jdbc driver (i-net Gate3 jdbc 3.0 driver for Oracle db)
https://www.inetsoftware.de/Download.htm

5 Development sample
We use different JDBC types to connect different database, there are type1 and type4
JDBC drivers, and two kinds of database: MySQL and Oracle. We will test all kinds
of connection methods and record the connection speed and the through-put in each
connection. The ten kinds of combinations as the following:
 MySQL JDBC-ODBC Bridge (Type1)
 MySQL Official Driver (Type4)
 MySQL JDBC-ODBC Bridge with connection pool (Type1)
 MySQL Official Driver with connection pool (Type4)
 Oracle 10g JDBC-ODBC Bridge (Type1)
 Oracle 10g Official Driver (Type4)
 Oracle 10g Official Driver (Type4)
 Oracle 10g i-net Gate3 Driver (Type4)
 Oracle 10g JDBC-ODBC Bridge with connection pool (Type1)
 Oracle 10g Official Driver with connection pool(Type4)
 Oracle 10g i-net Gate3 Driver with connection pool(Type4)

12
Figuer 8. The interface of the sample application

6 Results (Execution)
There are some results from the sample application, we do the process 20 times
for each combination of JDBC types and databases, records as the following figures.

6.1 Processing time


The processing time is a complete connection that include connecting to the
database、make a sql search and return、disconnection. The time unit is milli second
(Y axis).

13
 Different JDBC types connect with MySQL.

JDBC connect with MySQL

100

50

0
2nd
3rd
4th
5th
6th
7th
8th
9th
10th
11th
12th
13th
14th
15th
16th
17th
18th
19th
20th
1st

JDBC-ODBC Bridge (Type1) Official Driver(Type4)


JDBC-ODBC Bridge with connection pool(Type1) Official Driver with connection pool(Type4)

Figuer 9-1

 Different JDBC types connect with Oracle

JDBC connect with Oracle


550
450
350
250
150
50
t

5 th

7 th

9 th

th

th

th

th

th
1s

3r

11

13

15

17

19

JDBC-ODBC Bridge (Type1) Official Driver(Type4)


i-net Gate3 Driver(Type4) JDBC-ODBC Bridge with connection pool(Type1)
Official Driver with connection pool(Type4) i-net Gate3 Driver with connection pool(Type4)

Figuer 9-2

14
 JDBC-ODBC Bridge (Type1) connect with different database

JDBC-ODBC Bridge (Type1) connect with different database

500
400
300 MySQL
200 Oracle
100
0
t

th

th

th

th

th
1s

3r

5t

7t

9t

11

13

15

17

19
Figuer 9-3

 JDBC-ODBC Bridge with connection pool(Type1) connect with different


database

JDBC-ODBC Bridge with connection pool(Type1) connect with


different database

600
400 MySQL
200 Oracle

0
h

h
d
t

th

th

th

th

th
1s

5t

7t

9t
3r

11

13

15

17

19

Figuer 9-4

15
 JDBC Official Driver(Type4) connect with different database

JDBC Official Driver(Type4) connect with different database

150

100
MySQL
Oracle
50

0
d
t

th

th

th

th

th
1s

3r

5t

7t

9t

11

13

15

17

19
Figuer 9-5

 JDBC Official Driver with connection pool(Type4) connect with different


database

JDBC Official Driver with connection pool(Type4) connect with different


database

400
300
MySQL
200
Oracle
100
0
th

th

th

th

th
t

h
1s

3r

5t

7t

9t

11

13

15

17

19

Figuer 9-6

According to the result, we found that the processing time of typ1 and type4
JDBC driver when connecting with MySQL are almost the same. However, when
connecting with Oracle, type4 is obviously faster than type1. Using connection pool
to connect with database is faster than without. The processing time of MySQL is
faster than Oracle, no matter using what type of JDBC drivers.

16
6.2 Through-put and packet size
The through-put is the amount of packets before and after making connection.
We found that the packet size are differ from JDBC drivers, even the database are the
same, different JDBC drivers make difference between packet size. The result data
show as the following figures.

 The throughput of transferring packets

17
 The throughput of receiving packets

18
 The throughput of receiving Bytes

19
 The packet size of transferring

20
 The packet size of receiving

21
7 Alternatives
7.1 JDO
Java Data Objects (JDO) is a standard way to access persistent data in databases,
using plain old Java objects (POJO) to represent persistent data. The approach
separates data manipulation (done by accessing Java data members in the Java domain
objects) from database manipulation (done by calling the JDO interface methods).
This separation of concerns leads to a high degree of independence of the Java view
of data from the database view of the data.

Interfaces are defined for the user's view of persistence:

 PersistenceManager: the component responsible for the life cycle of


persistent instances, Query factory, and Transaction access.
 Query: the component responsible for querying the datastore and returning
persistent instances or values.
 Transaction: the component responsible for initiating and completing
transactions.

Commercial and open source implementations of JDO are available for relational
databases, object databases, and file systems.

7.2 Hibernate
Hibernate is an object-relational mapping (ORM) solution for the Java language:
it provides an easy to use framework for mapping an object-oriented domain model to
a traditional relational database. Its purpose is to relieve the developer from a
significant amount of relational data persistence-related programming tasks.

Hibernate is free as open source software that is distributed under the GNU Lesser
General Public License.

8 Discussion and Conclusion


To deal with daily transaction manipulations, good data processing and storing
technologies are both necessary to an enterprise. Nowadays, we face the distributed

22
architecture more often because of the strong growth of internet, which means a better
communication between two ends is very important. In the past, we used ODBC
(Open Database Connectivity) to accomplish this function, but now, JDBC becomes
the better choice when we facing the more complex environments and requirements.

We choose ORACLE and MySQL database as the testing object in this task. The
purpose is to measure the performance by using different types of drivers, trying to
find out a best way of communicating database.

One of the future works we can attempt is about the alternatives which we
mentioned on the previous paragraph. We can integrate maybe JDO and JDBC as the
major function when we taking a project about database access. Also, we can
comparison the performance between several mechanisms, and choosing the suitable
one for the enterprise.

9 Reference
[1] George Reese, Database programming with JDBC and Java.
Cambridge,O'Reilly,c1997
[2] Bernard Van Haecke JDBC 3.0 : Java database connectivity. New York,
NY :M&T Books,c2002.
[3] R. M. Menon, Expert Oracle JDBC Programming. Berkeley,
CA :Apress ;2005
[4] John O'Donahue, Java database programming bible, New York :Wiley,c2002.

23

Das könnte Ihnen auch gefallen