JDBC Tutorial

Java Database Connectivity (JDBC), is an API that let's Java program communicate with databases and manipulate it. It is important for all Java Programmers to know JDBC to be able to develop their applications.

JDBC Tutorial

Learn JDBC with this easy to understand and complete JDBC tutorial. Covering all the basic and advance concepts of database connectivity, this tutorial teaches JDBC with practical examples and programs.

Who is this JDBC Tutorial designed for?

This tutorial is designed for Java programmers at beginners and professional level. All freshers, BCA, BE, BTech, MCA and college students aspiring to learn Java programming will find JDBC concepts taught in this tutorial very useful. They can use it for developing notes, exam preparation, lab exercises, assignments and viva questions.

What do I need to know to begin with?

A basic knowledge of Java, SQL and Database concepts will be helpful to understand JDBC quickly.

JDBC syllabus covered in this tutorial

This JDBC tutorial covers:

Driver, Database Connection Steps, DriverManager Class, Statement Interface, ResultSet Interface, Transactions, Batch Processing, RowSet Interface, Java Data Object (JDO).

This is pretty much everything you need to know about JDBC. So, let start!

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.