Beruflich Dokumente
Kultur Dokumente
To connect with individual databases, JDBC (the Java Database Connectivity API)
requires drivers for each database. The JDBC driver gives out the connection to the
database and implements the protocol for transferring the query and result between client
and database.
Contents
[hide]
• 1 JDBC Architecture
o 1.1 Type 1 Driver - JDBC-ODBC bridge
1.1.1 Functions
1.1.2 Advantages
1.1.3 Disadvantages
o 1.2 Type 2 Driver - Native-API Driver specification
1.2.1 Advantages
1.2.2 Disadvantages
o 1.3 Type 3 Driver - Network-Protocol Driver
1.3.1 Functions
1.3.2 Advantages
1.3.3 Disadvantages
o 1.4 Type 4 Driver - Native-Protocol Driver
1.4.1 Functions
1.4.2 Advantages
1.4.3 Disadvantage
o 1.5 List of JDBC Drivers
o 1.6 See also
o 1.7 References
[edit] JDBC Architecture
The JDBC API contains two major sets of interfaces:
The JDBC type 1 driver, also known as the JDBC-ODBC bridge, is a database driver
implementation that employs the ODBC driver to connect to the database. The driver
converts JDBC method calls into ODBC function calls.
[edit] Functions
[edit] Advantages
• Almost any database for which ODBC driver is installed, can be accessed.
• A type 1 driver is easy to install.
[edit] Disadvantages
• Performance overhead since the calls have to go through the JDBC overhead
bridge to the ODBC driver, then to the native db connectivity interface.
• The ODBC driver needs to be installed on the client machine.
• Considering the client-side software needed, this might not be suitable for applets.
• Will not be suitable for Java applets.
The JDBC type 2 driver, also known as the Native-API driver, is a database driver
implementation that uses the client-side libraries of the database. The driver converts
JDBC method calls into native calls of the database API.
The type 2 driver is not written entirely in Java as it interfaces with non-Java code that
makes the final database calls. The driver is compiled for use with the particular
operating system. For platform interoperability, the Type 4 driver, being a full-Java
implementation, is preferred over this driver.
However the type 2 driver provides more functionality and better performance than the
type 1 driver as it does not have the overhead of the additional ODBC function calls.
[edit] Advantages
better performance than the type 1 driver as it does not have the overhead of the
additional ODBC function calls.
[edit] Disadvantages
The JDBC type 3 driver, also known as the Pure Java Driver for Database Middleware, is
a database driver implementation which makes use of a middle tier between the calling
program and the database. The middle-tier (application server) converts JDBC calls
directly or indirectly into the vendor-specific database protocol.
This differs from the type 4 driver in that the protocol conversion logic resides not at the
client, but in the middle-tier. Like type 4 drivers, the type 3 driver is written entirely in
Java. The same driver can be used for multiple databases. It depends on the number of
databases the middleware has been configured to support. The type 3 driver is platform-
independent as the platform-related differences are taken care by the middleware. Also,
making use of the middleware provides additional advantages of security and firewall
access.
[edit] Functions
[edit] Advantages
• Since the communication between client and the middleware server is database
independent, there is no need for the vendor db library on the client machine. Also
the client to middleware need not be changed for a new database.
• The Middleware Server (which can be a full fledged J2EE Application server) can
provide typical middleware services like caching (connections, query results, and
so on), load balancing, logging, auditing etc.
• Eg. for the above include jdbc driver features in Weblogic.
o Can be used in internet since there is no client side software needed.
o At client side a single driver can handle any database. (It works provided
the middleware supports that database!)
[edit] Disadvantages
The JDBC type 4 driver, also known as the Direct to Database Pure Java Driver, is a
database driver implementation that converts JDBC calls directly into the vendor-specific
database protocol.
The type 4 driver is written completely in Java and is hence platform independent. It is
installed inside the Java Virtual Machine of the client. It provides better performance
over the type 1 and 2 drivers as it does not have the overhead of conversion of calls into
ODBC or database API calls. Unlike the type 3 drivers, it does not need associated
software to work.
[edit] Functions
• Type 4 drivers are entirely written in Java that communicate directly with a
vendor's database, usually through socket connections. No translation or
middleware layers are required, improving performance.
• The driver converts JDBC calls into the vendor-specific database protocol so that
client applications can communicate directly with the database server.
• Completely implemented in Java to achieve platform independence.
• e.g. include the widely used Oracle thin driver - oracle.jdbc.driver.OracleDriver
which connect to jdbc:oracle:thin URL format.
• Client -> Native protocol JDBC Driver -> Database server
[edit] Advantages
• These drivers don't translate the requests into an intermediary format (such as
ODBC), nor do they need a middleware layer to service requests. Thus the
performance may be considerably improved.
• All aspects of the application to database connection can be managed within the
JVM; this can facilitate easier debugging.
[edit] Disadvantage
<JDBCConnectionPool CapacityIncrement="1"
DriverName="oracle.jdbc.driver.OracleDriver" InitialCapacity="3"
Password="blah blah"
Properties="user=USERNAME;dll=ocijdbc8;protocol=thin"
RefreshMinutes="5" Targets="myserver"
TestConnectionsOnReserve="true" TestTableName="dual"
URL="jdbc:oracle:thin:@database connect string"/>
Skip to Content Sun
Sun.com
About Sun
Downloads
Products
Solutions
Support
Training
Java
Java for your computer
Stay up to date with the latest versions of Java for your desktop computer.
Free and Open Source Java
Get your own copy of the underlying software code for the Java language.
Download the latest JDK
The basic developer kit for Java developers.
Download the Java EE SDK
The SDK supports Java SE 6 and the latest Java EE 5 technologies.
Download NetBeans IDE
Get the award-winning, open-source tool suite for developing Java applications.
Java Developer Resources
Visit java.sun.com for everything you need to know about the Java technology.
Java Developer Tools
See and download all software tools available from Sun.
Java Standard Edition
For developing and deploying Java applications for the desktop, servers, embedded, and
real-time environments.
Java Enterprise Edition
For enterprise, server-side Java applications.
Java Micro Edition
For Java applications running on mobile devices.
Java Training
Sharpen your Java skills with courses from the source.
Java Support
Get dedicated help from Sun including technical assistance, product support, and support
for deployed Java applications.
Solaris
OpenSolaris
Download, develop and collaborate with OpenSolaris
Solaris
Download the most advanced operating system in the world
Sun Studio
Optimizing compilers and tools for C/C++/Fortran application development
Solaris Developer Center
Explore the resources and community available to the Solaris developer.
Sun Developer Services
Get technical assistance, product support, training, and other services from the source.
BigAdmin
A community site with Solaris system administration information, hardware
compatibility, a script library, and other resources for administrators of Sun products.
Communities
OpenJDK
The place to collaborate on the open-source JDK, an implementation of the Java
Platform, Standard Edition specification.
Mobile & Embedded
The Mobile & Embedded Community enables and empowers developers to collaborate
and innovate, driving the evolution and adoption of the Java(TM) Platform, Micro
Edition (Java ME) for mobile and embedded devices.
GlassFish
The GlassFish community is building free, open source, production-quality, enterprise
software.
NetBeans
You have the opportunity to submit bugs and feature requests in IssueZilla, submit news
for the NetBeans Community, and contribute code or even create a project of your own.
Welcome to the team!
OpenSolaris
The OpenSolaris source code is already cutting edge, but innovation happens
everywhere, so we welcome your involvement.
OpenSPARC
OpenSPARC.net is the genesis of a vision to create a larger community where open
conversations and collaborative development projects spawn dramatic innovations around
chip design.
Open Storage
The OpenSolaris storage community is your gateway to data management related
communities and projects - file sharing, file systems, volume managers, data services,
storage drivers, and much more.
OpenJFX
Project OpenJFX is a community for sharing early versions of the JavaFX Script
language and for collaborating on its development.
java.net
A gathering place for Java technology enthusiasts and existing communities across
industries, platforms, and interest groups.
Sun Student Developers
The SDN Academic Developer Program offers you ready access to tools, resources, and
student communities.
Java Community Process
The JCP gives you a chance to both have your own work become an official component
of the Java platform, and to offer suggestions for improving and growing the technology.
My SDN Account
Update My Profile
Join SDN
Join SDN Now
Why Join
Becoming an Sun Developer Network (SDN) member makes you part of a vibrant
worldwide community of developers, and gives you access to cool stuff and exclusive
offers.
Top of Form
utf-8 main-developer-a
» search tips
Bottom of Form
APIs
Java SE
Java EE
Java ME
Solaris
Sun Studio Compilers & Tools
Web Services
Java Card
See All »
Downloads
Early Access
Java SE
Java EE
Java ME
JavaFX
Solaris
NetBeans
Sun Studio Compilers & Tools
MySQL
VirtualBox
See All »
Products
Java SE
Java SE for Business
Java SE for Embedded
Java Real-Time System
Java EE
Java ME
JavaFX
Scripting
Solaris
Sun Studio Compilers & Tools
NetBeans IDE
Open Storage
Mobility
MySQL
Java DB
See All »
Support
Big Admin
Developer Services
Forums
Globalization
See All »
Training
Certification
Developer Training
See All »
Participate
Forums
Blogs
Wikis
Java User Groups
Newsletters
Events
See All »
SDN Home > Products & Technologies > Java Technology > J2EE > JDBC > Learning
> Tutorial and Code Camps > jGuru: JDBC 2.0 Fundamentals >
Tutorials
jGuru: JDBC 2.0 Fundamentals
Print-friendly Version
Short Course
by
[About This Course| Exercises]
Course Outline
Introduction to JDBCTM
SQL
ODBC
The Java Programming Language and JDBC
JDBC 1.0
JDBC 2.0
A Complete Example
Describing the Scenario
Creating a Database
Connecting to the Database
Creating a Table
Inserting Information into a Database
Step by Step
Retrieving Information from a Database
Data Navigation
Data Extraction
Connecting a Java Program to a Database
Areas Controlled by the Connection Interface
Generalizing Connection Information
Statements, ResultSets, and Interacting with a Database
Modifying Data
Database Queries
Prepared Statements
Java-SQL Type Equivalence
JDBC Exception Types and Exception Handling
SQL Exceptions
SQL Warnings
Data Truncation
Sample Error Test Outcomes
Metadata
Database Metadata
ResultSet Metadata
Escape Syntax and Scalar Functions
Stored Procedures
MetaData Support
Parameter INs and OUTs
Escape Syntax
CallableStatement
Setup, Invocation, and Value Retrieval
Transactions
Commit
Rollback
Concurrency
Typical Transaction Code
Batch Update Facility
Typical Batch Update Code
Handling BatchUpdateException
Typical BatchUpdateException Handler
Scrollable Result Sets
Usage Notes
LOBs
Locators
Clob
Blob
SQL Conformance
The JDBC 2.0 Optional Package and J2EE
Using JDBC with JavaServer Pages
Sun Developer R
Feeds
Feedback
Click here to
rate this page