[go: up one dir, main page]

100% found this document useful (1 vote)
769 views15 pages

JDBC Api Components and Drivers

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 15

JDBC API

COMPONENTS
AND DRIVERS
JDBC Architecture
JDBC API COMPONENTS

◦ 1. DriverManager
◦ 2. Driver
◦ 3. Connection
◦ 4. Statement
◦ 5. ResultSet
◦ 6. SQLException
DriverManager 

◦ This class manages a list of database drivers.


◦ Matches connection requests from the java application with the
proper database driver using communication subprotocol.
◦ The first driver that recognizes a certain subprotocol under JDBC
will be used to establish a database Connection.
Driver

◦ This interface handles the communications with the database server.


◦ You will interact directly with Driver objects very rarely. Instead,
you use DriverManager objects, which manages objects of this
type.
◦ It also abstracts the details associated with working with Driver
objects.
Connection

◦ This interface with all methods for contacting a database.


◦ The connection object represents communication context, i.e., all
communication with database is through connection object only.
Statement

◦ You use objects created from this interface to submit the SQL
statements to the database.
◦ Some derived interfaces accept parameters in addition to executing
stored procedures.
ResultSet

◦ These objects hold data retrieved from a database after you execute
an SQL query using Statement objects.
◦ It acts as an iterator to allow you to move through its data.
SQLException

◦ This class handles any errors that occur in a database application.


JDBC Drivers Types

◦ Type 1 − JDBC-ODBC Bridge Driver


◦ Type 2 − JDBC-Native API
◦ Type 3 − JDBC-Net pure Java
◦ Type 4 − 100% Pure Java
Type 1 − JDBC-ODBC Bridge Driver
◦ When Java first came out, this
was a useful driver because
most databases only supported
ODBC access
◦ A JDBC bridge is used to
access ODBC drivers installed
on each client machine.
Type 2 − JDBC-Native API

◦JDBC API calls are converted into


native C/C++ API calls, which are
unique to the database. 
◦If we change the Database, we have
to change the native API, as it is
specific to a database
◦It eliminates ODBC's overhead.
Type 3 − JDBC-Net pure Java
◦ A three-tier approach is used to
access databases.
◦ JDBC clients use standard network
sockets to communicate with a
middleware application server.
◦ Application server translates and
forwards this to the database server.
◦ Extremely flexible
Type 4 − 100% Pure Java (Thin Driver)
◦ Pure Java-based driver communicates
directly with the DB through socket
connection.
◦ This is the highest performance driver
◦ This kind of driver is extremely flexible.
No need to install special software on the
client or server
Which Driver should be Used?
◦ If you are accessing one type of database, such as Oracle, Sybase, or IBM,
the preferred driver type is 4.
◦ If your Java application is accessing multiple types of databases at the
same time, type 3 is the preferred driver.
◦ Type 2 drivers are useful in situations, where a type 3 or type 4 driver is
not available yet for your database.
◦ The type 1 driver is not considered a deployment-level driver, and is
typically used for development and testing purposes only.

You might also like