JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases.
The JDBC library includes APIs for each of the tasks mentioned
below that are commonly associated with database usage.
ü Making
a connection to a database.
ü Creating
SQL or MySQL statements.
ü Executing
SQL or MySQL queries in the database.
ü Viewing
& Modifying the resulting records.
Why use JDBC
Before JDBC, ODBC API was the database API to connect and execute 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).
What is API
API (Application programming interface) is a document that contains description of all the features of a product or software. It represents classes and interfaces that software programs can follow to communicate with each other. An API can be created for applications, libraries, operating systems, etc.
Pre-Requisite
Before moving further, you need to have a good understanding of the following two subjects −
- Core JAVA Programming
- SQL or MySQL Database
JDBC Architecture
The JDBC API supports both two-tier and three-tier processing models for database access but in general, JDBC Architecture consists of two layers −
The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous databases.
The JDBC driver manager ensures that the correct driver is used to access each data source. The driver manager is capable of supporting multiple concurrent drivers connected to multiple heterogeneous databases.
Following is the architectural diagram, which shows the location of the driver manager with respect to the JDBC drivers and the Java application −
Common JDBC Components
The JDBC API provides the following interfaces and classes −
ü DriverManager: This class manages a list of database
drivers. Matches connection requests from the java application with the proper
database driver using communication sub protocol. 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.
0 comments:
Post a Comment