Introduction to JDBC

Aniket GudgalAniket Gudgal
2 min read

JDBC stands for Java Database Connectivity. It is a standard API provided by Oracle for Java applications to interact with different sets of database

Architecture of JDBC

  1. Application: It is a Java applet or a servlet that communicates with a data source.

  2. The JDBC API: The JDBC API allows Java programs to execute SQL statements and retrieve results. Some of the important interfaces defined in JDBC API are as follows: Driver interface, ResultSet Interface, RowSet Interface, PreparedStatement interface, Connection inteface, and classes defined in JDBC API are as follows: DriverManager class, Types class, Blob class, club class.

  3. DriverManager: It plays an important role in the JDBC architecture. It uses some database-specific drivers to connect enterprise applications to databases effectively.

  4. JDBC drivers: To communicate with a data source through JDBC, you need a JDBC driver that intelligently communicates with the respective data source.

Types of JDBC Architecture(2-tier and 3-tier)

  1. Two-tier model: A Java application communicates directly to the data source. The JDBC driver enables the communication between the application and the data source. When a user sends a query to the data source, the answers for those queries are sent back to the user in the form of results.
    The data source can be located on a different machine on a network to which a user is connected. This is known as a client/server configuration, where the user’s machine acts as a client, and the machine has the data source running acts as the server.

  2. Three-tier model: The user’s queries are sent to middle-tier services, from which the commands are again sent to the data source. The results are sent back to the middle tier and then to the user.

There are four types of JDBC drivers:

  1. JDBC-ODBC Bridge Driver

  2. Native Driver

  3. Network Protocol Driver

  4. Thin Driver

The java.sql package contains classes and interfaces for JDBC API

  1. Driver interface

  2. Connection interface

  3. Statement interface

  4. PreparedStatement interface

  5. CallableStatement interface

  6. ResultSet interface

  7. ResultSetMetaData interface

  8. DatabaseMetaData interface

  9. RowSet interface

The question comes to mind why do we use the JDBC?

the simple answer is that communication between two different languages is not possible. java can not be communicated to the database language directly that's why the JDBC comes to solve this problem

I have installed the JDBC driver MySQL connector on my machine

10
Subscribe to my newsletter

Read articles from Aniket Gudgal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aniket Gudgal
Aniket Gudgal