You are on page 1of 20

Advanced JAVA

JDBC
Introduction : JDBC

• JDBC(Java Database Connectivity) is a data API for the Java


programming language.
• It is an interface that helps a client to access a database system, by
providing methods to query and update data in the databases.
• JDBC is more suitable for object oriented databases
JDBC Driver

• JDBC Driver is a software component that enables java application to interact with the
database.
• The JDBC specification related API in the form of java.sql package.
• Each JDBC driver is set of classes implementing various interfaces of JDBC API packages.
While defining methods of these interfaces the classes contain logic to interact with specific
database software. JDBC uses jar files.
• A JAR (Java ARchive) file is a file that contains the class, image, and sound files for a Java
application or applet gathered into a single file and possibly compressed.
• When a programmer gets a Java program development kit, a small program or utility called
"jar" is included.
Difference between ODBC and JDBC

• OBDC is Microsoft drivers and uses dlls, JDBC is Java drivers and uses
jar files.
• ODBC is procedural oriented and JDBC is object oriented.
• ODBC can't be directly used with Java because it uses a C interface.
• ODBC makes use of pointers which have been removed totally from Java.
• ODBC mixes simple and advanced features together and has complex
options for simple queries.
• But JDBC is designed to keep things simple while allowing advanced
capabilities when required.
….
• ODBC requires manual installation of the ODBC driver manager and driver
on all client machines.
• JDBC drivers are written in java and JDBC code is automatically installable,
secure, and portable on all platforms.
• JDBC API is a natural Java Interface and is built on ODBC. JDBC retains
some of the basic feature of ODBC.
• JDBC is Java Database Connectivity. It enables java programs to execute
SQL statements. JDBC makes it possible to write a single database
application that can run on different platforms and interact with different
DBMS.
• JDBC is language dependent i.e it is used only to make connectivity with
java. ODBC is open database connectivity. The goal of ODBC is to make
it possible to access any data from any application, regardless of which
database management system (DBMS) is handling the data so it is
language independent.
• ODBC is language independent and JDBC is language dependent.
JDBC Drivers
JDBC API

• The JDBC API is a Java API for accessing virtually any kind of tabular data. (As a
point of interest, JDBC is the trademarked name and is not an acronym; nevertheless,
JDBC is often thought of as standing for "Java Database Connectivity.")
• The JDBC API makes it easy to send SQL statements to relational database systems
and supports all dialects of SQL.
• The value of the JDBC API is that an application can access virtually any data source
and run on any platform with a Java Virtual Machine.
• JDBC API provides a standard abstraction for Java application to access JOBC
drivers, which is implemented by 3rd party vendor, i.e., database.
• JDBC API defines a standard protocol between a Java application and JDBC driver.
Goal of JAVA-API

Important Goals of JDBC-API


• Provides a standard abstraction for submitting the SQL statements to access the data is
database.
• Maintains focus on SQL.
• Support the compatibility with connectors.
• Provides a foundation for high-level API and keep it simple.
Types of JDBC Drivers

There are 4 types of JDBC drivers:


1. Type-1 or JDBC-ODBC bridge driver
2. Type-2 or Native-API driver (partially java driver)
3. Type-3 or Network Protocol driver (fully java driver)
4. Type-4 or Thin driver (fully java driver)
JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-
ODBC bridge driver converts JDBC method calls into the ODBC function calls.
This is now discouraged because of thin driver.
Advantages:
• easy to use.
• can be easily connected to any database.
Disadvantages:
• Performance degraded because JDBC method call is converted into the ODBC function
calls.
• The ODBC driver needs to be installed on the client machine.
JDBC-ODBC bridge driver
Native-API driver

The Native API driver uses the client-side libraries of the


database.
The driver converts JDBC method calls into native calls of
the database API. It is not written entirely in java.
Advantage:
• Performance upgraded than JDBC-ODBC bridge driver.
Disadvantage:
• The Native driver needs to be installed on the each client
machine.
• The Vendor client library needs to be installed on client
machine.
Network Protocol driver
The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or indirectly
into the vendor-specific database protocol. It is fully written in java.
Advantage:
• No client side library is required because of application server that can perform many tasks like auditing, load
balancing, logging etc.
Disadvantages:
• Network support is required on client machine.
• Requires database-specific coding to be done in the middle tier.
• Maintenance of Network Protocol driver becomes costly because –
it requires database-specific coding to be done in the middle tier.
Thin Driver
The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is
known as thin driver. It is fully written in Java language.
Advantage:
• Better performance than all other drivers.
• No software is required at client side or server side.
Disadvantage:
• Drivers depends on the Database.
Two-Tier and Three-Tier Client/Server Model

The JDBC API supports both two-tier and three-tier models for
database access.
• Two-Tier Model
• In the two-tier model, a Java applet or application talks directly to
the data source.
• This requires a JDBC driver that can communicate with the
particular data source being accessed.
• A user's commands are delivered to the database or other data
source, and the results of those statements are sent back to the user.
• The data source may be located on another machine to which the
user is connected via a network.
• This is referred to as a client/server configuration, with the user's
machine as the client, and the machine housing the data source as
the server.
• The network can be an intranet, which, for example, connects
employees within a corporation, or it can be the Internet.
Three-Tier Model
• Commands are sent to a "middle tier" of services, which then sends the commands to the data
source.
• The data source processes the commands and sends the results back to the middle tier, which
then sends them to the user.
• MIS directors find the three-tier model very attractive because the middle tier makes it possible
to maintain control over access and the kinds of updates that can be made to corporate data.
• Another advantage is that it simplifies the deployment of applications. Finally, in many cases,
the three-tier architecture can provide performance advantages.
Three-Tier Model
• With enterprises increasingly using the Java programming language for writing server code
• JDBC API is being used more and more in the middle tier of a three-tier architecture. Some of
the features that make
• JDBC a server technology are its support for connection pooling, distributed transactions, and
disconnected rowsets. And, of course, the JDBC API is what allows access to a data source
from a Java middle tier.
THANK YOU

You might also like