JDBC stands for Java Database Connectivity, a Java API built for running database queries and managing database connections. It is regarded as part of Java SE, the Java Standard Edition. The JDBC API relies on JDBC drivers to reach the database. The four kinds of JDBC drivers are listed below:
JDBC-ODBC bridge driver
JDBC Thin JDBC driver
Local driver and
Network Protocol Driver
The JDBC API lets you reach tabular data held in any relational database. Through it you can store, update, delete, and retrieve records in the database. For that reason it is viewed as an Open Database Connectivity (ODBC) interface supplied by Microsoft.
JDBC connects an application to the database and lets you store and retrieve data by way of queries. Users can also modify data through those queries. This made it possible to carry out all these tasks inside a Java application.
It makes connecting to the data source straightforward.
It lets you send requests and update notifications.
It helps you pull data from the database and process the results with ease.
By calling classes and JDBC interfaces from the Java application, you can send SQL queries and requests and then retrieve the results. The JDBC driver is what implements the JDBC API. This driver is made up of a set of classes that implement the JDBC interface. It processes JDBC calls and passes the outputs/results back to the Java application. A database is a storage system where all the data can be kept, and JDBC can be used to retrieve that data for use in an application.
Before JDBC existed, the ODBC API was used to connect to databases and run queries. But the ODBC API relies on the ODBC module of the C language, which is platform dependent and not secure. That is why Java created its own JDBC API, which links an application to a database through JDBC drivers. These drivers are written in Java as well.
It supports both two-level and three-level processing models for database access. Its overall architecture, however, is made up of the two layers listed below:
This layer handles connecting the application to the JDBC manager. A management driver together with database-specific drivers delivers transparent access to heterogeneous databases.
This layer supplies the connection to the JDBC driver. The driver handler makes sure the right driver reaches each data source. The JDBC Driver API can support various driver types, each of which can connect to a different database.
It is built from the following interfaces and classes, which can be described as its components.
The driver manager is responsible for keeping the list of drivers in a database. It also relies on a communication protocol to coordinate connection requests between the Java application and the database driver. To connect to the database, the first driver that understands the JDBC sub-protocol is created.
The driver is the interface that manages communication between the application and the database server. Direct communication with the control object is very rare, since the control object is typically the most used object.
The contact interface, together with all its methods, is used to connect to the database. The contact object stands for the communication context, which means communication with the database happens only through the contact object.
Objects built with this interface are able to send SQL commands to the database. Certain derived interfaces also accept parameters when a particular stored procedure is invoked.
The ResultSet object holds data retrieved from the database, which is done with the Statement object once the SQL query has run. It also works as an iterator, letting you step through the data.
The SQL Exception class handles errors that arise in a database program.
JDBC offers many advantages; a few of them are listed here
Businesses can keep using their installed database and still access information even when it lives in another database management system.
Pairing the Java API with the JDBC API makes application development simpler and more convenient.
No client-side configuration is needed, and software support can be centralized. Because the driver is written in Java, the only detail required to establish a connection is specified in the JDBC or DataSource object URL. The DataSource object is registered through the Java Naming and Directory Interface (JNDI) service.
Gaining insight into the basic structure and functionality of database connections is easier because the JDBC API provides access to metadata and makes building complex applications possible.