Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

JDBC stands for Java Database Connectivity.

JDBC is a Java API to connect and execute


the query with the database. It is a part of JavaSE (Java Standard Edition). JDBC API uses
JDBC drivers to connect with the database. There are four types of JDBC drivers:

o DBC-ODBC Bridge Driver,


o Native Driver,
o Network Protocol Driver, and
o Thin Driver

We have discussed the above four drivers in the next chapter.

We can use JDBC API to access tabular data stored in any relational database. By the
help of JDBC API, we can save, update, delete and fetch data from the database. It is
like Open Database Connectivity (ODBC) provided by Microsoft.

The current version of JDBC is 4.3. It is the stable release since 21st September, 2017.
It is based on the X/Open SQL Call Level Interface. The java.sql package contains
classes and interfaces for JDBC API. A list of popular interfaces of JDBC API are given
below:

o Driver interface
o Connection interface
o Statement interface
o PreparedStatement interface
o CallableStatement interface
o ResultSet interface
o ResultSetMetaData interface
o DatabaseMetaData interface
o RowSet interface
A list of popular classes of JDBC API are given below:

o DriverManager class
o Blob class
o Clob class
o Types class

Why Should We Use JDBC


Before JDBC, ODBC API was the database API to connect and execute the query with
the database. But, ODBC API uses ODBC driver which is written in C language (i.e.
platform dependent and unsecured). That is why Java has defined its own API (JDBC
API) that uses JDBC drivers (written in Java language).

We can use JDBC API to handle database using Java program and can perform the
following activities:

1. Connect to the database


2. Execute queries and update statements to the database
3. Retrieve the result received from the database.

java.sql: This package provides APIs for data access and data
process in a relational database, included in
Java Standard Edition (java SE)

javax.sql: This package extends the functionality of java package


by providing datasource interface for
establishing connection pooling, statement
pooling with a data source, included in
Java Enterprise Edition (java EE)
It also provides a standard to connect a database to a client application.
2. JDBC Driver manager: It loads a database-specific driver in an
application to establish a connection with a database. It is used to make a
database-specific call to the database to process the user request.
3. JDBC Test suite: It is used to test the operation(such as insertion,
deletion, updation) being performed by JDBC Drivers.
4. JDBC-ODBC Bridge Drivers: It connects database drivers to the
database. This bridge translates the JDBC method call to the ODBC function
call. It makes use of the sun.jdbc.odbc package which includes a native
library to access ODBC characteristics.
Architecture of JDBC
Description:
1. Application: It is a java applet or a servlet that communicates with a data
source.
2. The JDBC API: The JDBC API allows Java programs to execute SQL
statements and retrieve results. Some of the important classes and
interfaces defined in JDBC API are as follows:
3. DriverManager: It plays an important role in the JDBC architecture. It
uses some database-specific drivers to effectively connect enterprise
applications to databases.
4. JDBC drivers: To communicate with a data source through JDBC, you
need a JDBC driver that intelligently communicates with the respective
data source.
Types of JDBC Architecture(2-tier and 3-tier)
The JDBC architecture consists of two-tier and three-tier processing
models to access a database. They are as described below:
1. Two-tier model: A java application communicates directly to the data
source. The JDBC driver enables the communication between the
application and the data source. When a user sends a query to the data
source, the answers for those queries are sent back to the user in the
form of results.
The data source can be located on a different machine on a network to
which a user is connected. This is known as a client/server
configuration, where the user’s machine acts as a client, and the
machine has the data source running acts as the server.

2. Three-tier model: In this, the user’s queries are sent to middle-tier


services, from which the commands are again sent to the data source.
The results are sent back to the middle tier, and from there to the user.
This type of model is found very useful by management information
system directors.

You might also like