JDBC (Java DataBase Connectivity)
Overview
JDBC stands for Java Data*B*ase Connectivity , it is the standard API
for connection between the Java programming language and wide range of databases, including:
Oracle, Mysql, PostgreSql, Sqlite ...
JDBC Architecture
JDBC API consists of two layers:
- JDBC API: Provide Java application to JDBC Manager connection.
- JDBC Driver API: Provide JDBC Manager to Driver Connection.
Each Database (Oralce, Mysql ...) has its Driver, which needs a DriverManger to ensure that
each Database use its driver.
Here is a Driagram representing the JDBC Architecture:
JDBC Components
JDBC API provides the following classes and interfaces:
- DriverManager (Class) : This class manages the list of databases drivers.
- Driver (Interface): This interface handles the connection with the database, you will use this interface rarely. Instead you will use the DriverManager object to connect with the database.
- Connection (Interface): This interface represents the connection between the java application and the database. All communication with the database is through this object.
- Statement (Interface): You use object created from this interface to create SQL queries.
- ResultSet (Class): This object holds data retunred from the databse, it acts as an iterator.
- SQLException (Exception class): This class handls any error that occurs while connecting to the database.
- ## Drivers In order to connect to a specific database. We need to load it's driver through a .jar file
If you are using IntellijIDEA, You can import the jar file by:
Edit> Project Structure > Libraries > + > Java > *select the jar file*
We need also the jdbc driver name and db url, here is a summary:
Top comments (0)