JDBC  «Prev  Next»
Lesson 4JDBC drivers
ObjectiveDefine the three functions that JDBC drivers perform in the data request process.

JDBC Drivers

JDBC tries to minimize the number of details that a developer needs to worry about. A common approach to this goal is to specify the layers at which various common activities occur and then to tightly define how those layers will interact with one another and with a program. JDBC takes this approach. JDBC specifies that most of the details about communicating with a database system will be handled through a software layer called a driver. This driver will handle the details of the three basic tasks we need to do to work with a database:
  1. Create and maintain a connection to a database
  2. Send our commands to that database
  3. Deliver the database response back to our program

JDBC Driver Connectivity

A database vendor provides the APIs for accessing the data managed by the database server. A JDBC driver is a middleware used to translate JDBC commands into the vendor's API, send them off to the database, and then return the result.
Despite the fact that database vendors use different APIs, we use a common set of methods to invoke an appropriate JDBC driver. The driver will perform the job of translating to the required API. The JDBC driver performs three different functions in the data request process, as illustrated in the Slide Show below.


Connectivity using JDBC Driver
1) JDBC DriverManager provides the application with a connection to a database via Connection object
1) JDBC DriverManager provides the application with a connection to a database via Connection object

2) JDBC Driver translates the call from the application and routes it to the database.
2) JDBC DriverManager provides the application with a connection to the database via a Connection object.

3) JDBC Driver collects and translates the database response, routing it back to the application
3) JDBC Driver collects and translates the database response, routing it back to the application.

Which components are needed to make a JDBC connection to an Oracle Database

To make a JDBC connection to an Oracle database, you need the following components:
  1. Oracle JDBC Driver: A software component that implements the Java Database Connectivity (JDBC) API and allows Java applications to connect to an Oracle database.
  2. Oracle Database: The database management system where your data is stored.
  3. Java Development Kit (JDK): The software development kit that includes the Java Virtual Machine (JVM) and the Java compiler, among other tools.
  4. Java Application: The application that you want to use to connect to the Oracle database.
  5. Connection URL: A string that specifies the location of the Oracle database and the format of the connection.
  6. Java Database Connectivity (JDBC) API: A Java API that provides a standard interface for accessing databases from Java applications.
Once you have these components, you can use JDBC to establish a connection to the Oracle database and execute SQL statements to retrieve, update, and manipulate data.
To make a JDBC connection to an Oracle database, you need the following components:

DriverManager

DriverManager : this fully implemented class was introduced in the original JDBC 1.0 API. When an application first attempts to connect to a data source by specifying a URL, DriverManager will automatically load any JDBC drivers found within the CLASSPATH (any drivers that are pre-JDBC 4.0 must be explicitly loaded by the application).


The JDBC API includes two major set of interfaces:
  1. A JDBC API for application developers
  2. A lower-level JDBC driver API for writing drivers
JDBC drivers are the implementation of the lower-level JDBC driver API as defined in the JDBC specifications. Depending on whether the drivers are implemented using only Java code, native code, or partial Java, they are categorized as follows:
  1. Type 4.pure Java JDBC driver
  2. Type 3.pure Java driver for database middleware
  3. Type 2.native API, partly Java driver
  4. Type 1.JDBC-ODBC bridge
In the next lesson, you will learn about the four types of JDBC drivers.

SEMrush Software