Beruflich Dokumente
Kultur Dokumente
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.
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.
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.
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
environment.
Figure5. Type 4 driver
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.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:
J2sdk 1.5:
http://java.sun.com/javase/downloads/?intcmp=1281
11
http://tomcat.apache.org/download-55.cgi
Oracle 10g:
http://www.oracle.com/technology/software/products/database/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.
13
Different JDBC types 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
Figuer 9-1
5 th
7 th
9 th
th
th
th
th
th
1s
3r
11
13
15
17
19
Figuer 9-2
14
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
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
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
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.
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.
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.
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