JDBC Tutorial

Introduction

Java Database Connectivity (JDBC) is an application programming interface (API) that helps Java program to communicate with databases and manipulates their data. The JDBC API provides the methods that can be used to send SQL and PL/SQL statements to almost any relational database. The latest version of JDBC is 4.2 that comes along with Java SE 8.

Purpose of JDBC API

  • To access tables and its data from relation database.
  • To send queries and update statement to database.
  • Obtain and modify the results to and from a JDBC application.
  • Find the metadata of the table.
  • Performing different operations on a database, like creating table, querying data, updating data, inserting data from a Java application.

Architecture of JDBC

The JDBC API supports both two-tier and three- tier architecture for database access.

Two-tier Architecture
Two-tier Architecture provides direct communication between Java applications to the database. It requires a JDBC driver that can help to communicate with the particular database.

jdbc two tier
Three-tier Architecture
In the three-tier model, commands are sent by the HTML browser to middle services i.e. Java application which can send the commands to the particular database. The middle tier has been written in C or C++ languages. It can also provide better performance.

jdbc three tier

JDBC Components

Following are the components of JDBC that help Java application connect with database.

JDBC API
The JDBC provides the various methods and interface for easy communication between Java application and database.

DriverManager
The DriverManager is a class that manages all database drivers.  It loads the specific database drivers in an application to establish connection with database.   

Connection
Connection is an interface that contains all methods for contacting with database.

JDBC Test Suite
The operation of every driver is different in Java applications. The JDBC test suit helps us to test the operation being performed by the JDBC drivers.

JDBC-ODBC Bridge
JDBC-ODBC Bridge provides a interface that helps to connect database drivers to the database.