DEV Community

ablil
ablil

Posted on

Overview of JDBC

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 Architecture Diagram

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:

Database JDBC Driver Name DB URL JAR file
Oracle oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@hostname:port:dbname download
MySql com.mysql.cj.jdbc.Driver jdbc:mysql://hostname/dbname download
Sqlite - jdbc:sqlite:/root/dbfile.db download

Top comments (0)