Lecture 17 - JDBC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ICT 1411

Object Oriented Programming


Lecture 17
Java Database Connectivity
Introduction to JDBC
● JavaSoft specification of a standard application programming interface (API)
that allows Java programs to access database management systems.
● The JDBC API consists of a set of interfaces and classes written in the Java
programming language.
● Using these standard interfaces and classes, programmers can write
applications that connect to databases, send queries written in structured
query language (SQL), and process the results.

Reference: https://www.youtube.com/watch?v=s7wmiS2mSXY
Architecture of JDBC
1) Application : It is the Java servlet or an applet that
communicates with the data source.
2) JDBC API
● The JDBC API is a set of classes and interfaces provided by Java for database
connectivity.
● Allows Java programs to interact with databases in a consistent and
platform-independent manner.
● DriverManager
○ The DriverManager class is a part of the JDBC API.
○ Acts as an interface between users and drivers.
○ It handles establishing a connection between a database and the appropriate
driver.
○ Used to establish a connection to a database using a JDBC URL.

3) JDBC driver

● The JDBC driver is a software component that provides the necessary interfaces for
the Java program to communicate with the database.
● The driver is specific to the type of database being used.
○ Ex: Java DB Driver - Derby, MySQL JDBC driver - MySQL DB
RDBMS: The RDBMS is the database management system that stores the data being
accessed by the Java program.

Ex: Derby, Microsoft SQL Server, Oracle, MySQL, and PostgreSQL.

In a typical scenario, a Java program uses the JDBC API to code the program. Through
JDBC driver the program can communicate with the RDBMS.

The database administrators can use to manage the SQL Server instance and perform
tasks related to the database.
A few of the crucial interfaces and classes defined in the JDBC API are the following:
● Statement
○ Statement is an interface that represents an SQL statement that is sent to
a database and executed.
○ It is used to execute SQL queries and updates.
● Connection
○ Connection is an interface that represents a connection to a database.
○ It is used to create Statement and PreparedStatement objects and to
manage transactions.
● PreparedStatement
○ PreparedStatement is an interface that represents a precompiled SQL statement
that can be executed multiple times with different parameters.
○ It is used to execute SQL queries and updates with parameters.
● ResultSet
○ ResultSet is an interface that represents a set of results from a database query.
○ It is used to retrieve data from the database.

You might also like