JDBC stands for Java Database Connectivity. It is a standard API provided by Oracle for Java applications
to interact with different set of databases. JDBC uses Structured Query Language(SQL) for performing database queries like database access, storage, update or delete.
Why do we need JDBC?
Java applications converse in Java language while Databases only understand Structured Query Language(SQL),
hence a Java application alone cannot communicate with a database unless there is an translation or interface
between a Java application and a database. This translation or interface is provided by JDBC.
How JDBC works?
When an application wants to communicate with a database for database access, storage or query, it executes Java commands and these java commands are translated
by JDBC to SQL statements, which is understood and executed by a database. The result of executing these SQL statements is sent back to JDBC, which converts it into a form which a Java application can easily comprehend.
JDBC architecture consists of two layers -
JDBC Application Layer
JDBC Application Layer consists of two components - Java application and JDBC API. In Application layer,
a java Application that wishes to communicate with a database uses the JDBC API to access the required JDBC driver.
The JDBC API contains the JDBC driver manager, which connects Java application with the JDBC driver. Please refer to Figure - 1.
JDBC Driver Layer
JDBC Driver Layer consists of several database drivers that may be required to connect a Java application to its choice of a specific database.
For example - the JDBC Driver Layer may contain a MySQL database driver, an Oracle driver and a MariaDB Database driver to connect any Java application
with any of these databases as per the requirement of this Java application.
This JDBC driver is nothing but a program through which a Java application can easily communicate with a database. This JDBC driver translates the requests
of a Java application such a database query like database access, update or storing procedures from Java language to Structured Query Language(SQL),
which is then forwarded to a specific database of choice of this Java application.
These SQL statements are executed by the preferred database and the result is sent back to JDBC driver.
The JDBC driver sends the result back to Java application(through JDBC API) in the form which it can easily understand.
Please refer to Figure - 1.