English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JDBC representsJAVA DATA bASE CConnectivity (Java Database Connectivity), it is a standard Java API for independent database connections between Java programming language and a large number of databases.
The JDBC library includes APIs for each of the tasks mentioned below, which are usually associated with database usage.
Establish a connection with the database.
Create SQL or MySQL statements.
Execute SQL or MySQL queries in the database.
View and modify result records.
In essence, JDBC is a specification that provides a complete set of interfaces, allowing portable access to the underlying database. Java can be used to write different types of executable files, such as-
Java Application
Java Applet
Java Servlet
Java ServerPage (JSP)
Enterprise JavaBean (EJB).
All these different executable files can access the database using JDBC drivers and make use of the stored data.
JDBC provides the same functionality as ODBC, allowing Java programs to include code independent of the database.
Before proceeding, you must have a thorough understanding of the following two topics-
The JDBC API supports two-tier and three-tier processing models for database access, but typically, the JDBC architecture consists of two layers-
JDBC API: This provides the connection from the application to the JDBC manager.
JDBC Driver API: This supports the connection from the JDBC manager to the driver.
The JDBC API uses the driver manager and database-specific drivers to provide transparent connections to heterogeneous databases.
The JDBC driver manager ensures that the correct driver is used to access each data source. The driver manager can support multiple concurrent drivers for connecting to multiple heterogeneous databases.
The following is an architecture diagram that shows the position of the driver manager relative to JDBC drivers and Java applications-
The JDBC API provides the following interfaces and classes-
DriverManager:This management database driver list. Match connection requests from Java applications with appropriate database drivers using communication subprotocols. The first driver that identifies a specific subprotocol under JDBC will be used to establish a database connection.
Driver:This interface handles communication with the database server. You rarely interact directly with the Driver object. Instead, you use the DriverManager object, which manages this type of object. It also abstracts the details related to using the Driver object.
Connection:This interface contains all the methods for contacting the database. The connection object represents the communication context, that is, all communication with the database is only through the connection object.
Statement:You can use objects created from this interface to submit SQL statements to the database. Some derived interfaces also accept parameters, in addition to executing stored procedures.
ResultSet:After executing SQL queries using the Statement object, these objects save the data retrieved from the database. It acts as an iterator, allowing you to traverse its data.
SQLException: This class handles all the errors that occur in database applications.
java.sql and javax.sql are JDBC 4The main package for .0. This is the latest JDBC version at the time of writing this tutorial. It provides the main classes for interacting with data sources.
The new features in these packages include the following changes in the following aspects:
Automatic Database Driver Loading.
Improvements in Exception Handling.
Enhanced BLOB / CLOB Functionality.
Enhanced Connection and Statement Interfaces.
National Character Set Support.
SQL ROWID Access.
SQL 2003 XML Data Type Support.
Annotations.