JDBC
JDBC
2/26/2024
What is JDBC
2/26/2024
Why Should We Use JDBC
• Before JDBC, ODBC API was the database API to connect and
execute the query with the database. But, ODBC API uses ODBC
driver which is written in C language (i.e. platform dependent and
unsecured). That is why Java has defined its own API (JDBC API)
that uses JDBC drivers (written in Java language).
We can use JDBC API to handle database using Java program and can
perform the following activities:
• Connect to the database
• Execute queries and update statements to the database
• Retrieve the result received from the database.
2/26/2024
JDBC API
• The java.sql package contains classes and interfaces for JDBC API.
List of popular interfaces list of popular Classes
2/26/2024
JDBC drivers
• JDBC drivers are client-side adapters (installed on the client machine, not
on the server) that convert requests from Java programs to a protocol that
the DBMS can understand. JDBC drivers are the software components
which implements interfaces in JDBC APIs to enable java application to
interact with the database.
• There are four types of JDBC drivers defined by Sun Microsystem that
are mentioned below:
1.Type-1 driver or JDBC-ODBC bridge driver
2.Type-2 driver or Native-API driver
3.Type-3 driver or Network Protocol driver
4.Type-4 driver or Thin driver
2/26/2024
JDBC-ODBC bridge driver – Type 1 driver
2/26/2024
JDBC-ODBC bridge driver – Type 1 driver
2/26/2024
Native-API driver
• The Native API driver uses the client-side libraries of the database.
The driver converts JDBC method calls into native calls of the
database API. It is not written entirely in java.
2/26/2024
Network Protocol driver
2/26/2024
Thin driver
• The thin driver converts JDBC calls directly into the vendor-specific
database protocol. That is why it is known as thin driver. It is fully
written in Java language.
2/26/2024
Java Database Connectivity
There are 7 steps to connect any java application with the database
using JDBC. These steps are as follows:
• Import the package for JDBC API
• Load and Register the Driver class
• Create connection
• Create statement
• Execute queries
• Process the result
• Close connection
2/26/2024
Java Database Connectivity step by step
2/26/2024
Java Database Connectivity step by step
2/26/2024
Java Database Connectivity step by step
2/26/2024
Java Database Connectivity step by step
2/26/2024