Architecture Design of JDBC
Architecture Design of JDBC
Components of JDBC
JDBC has four major components that are used for the interaction with the database.
1. JDBC API
2. JDBC Test Suite
3. JDBC Driver Manger
4. JDBC ODBC Bridge Driver
1) JDBC API: JDBC API provides various interfaces and methods to establish easy
connection with different databases.
1. javax.sql.*;
2. java.sql.*;
2) JDBC Test suite: JDBC Test suite facilitates the programmer to test the various
operations such as deletion, updation, insertion that are being executed by the JDBC
Drivers.
3) JDBC Driver manager: JDBC Driver manager loads the database-specific driver
into an application in order to establish the connection with the database. The JDBC
Driver manager is also used to make the database-specific call to the database in
order to do the processing of a user request.
4) JDBC-ODBC Bridge Drivers: JDBC-ODBC Bridge Drivers are used to connect the
database drivers to the database. The bridge does the translation of the JDBC
method calls into the ODBC method call. It makes the usage of the sun.jdbc.odbc
package that encompasses the native library in order to access the ODBC (Open
Database Connectivity) characteristics.
Architecture of JDBC
1) Application: It is the Java servlet or an applet that communicates with the data
source.
2) The JDBC API: It allows the Java programs to perform the execution of
the SQL statements and then get the results.
A few of the crucial interfaces and classes defined in the JDBC API are the following:
o Drivers
o DriverManager
o Statement
o Connection
o CallableStatement
o PreparedStatement
o ResultSet
o SQL data
Two-tier model: In this model, the application interacts directly with the source of
data. The JDBC driver establishes the interaction between the data source and the
application. When a query is sent by the user to the data source, the reply of those
sent queries is sent directly to the user.
The source of data can be located on a different machine, and that machine is
connected to the user machine following a client-server paradigm, where the
machine which is sending the query is the client machine, and the machine that is
sending the result of those queries is acting as the server.
Three-tier model: In this model, the queries of the user are being sent to the
middle-tier services, from where the commands are sent again to the source of data.
The answers to those queries are reverted to the middle tier, and from there, it is
again sent to the user.
JDBC Working
Any Java application that needs to interact with a database needs to be programmed
using the JDBC API. The JDBC driver that supports the data sources like Oracle or
MySql needs to be added; then, only the interaction happens with the data source.
FileName: JDBCExample.java
Output:
Explanation: The above Java application connects to the MySQL Database System.
Therefore, we need the driver for MySQL in order to access the data. That driver
(com.mysql.jdbc.Driver) is provided in the mysqlconnector.jar file, which must be
included in the classpath when the above program is executed. Similarly, if instead of
MySQL had we used Oracle, then the drivers corresponding to Oracle must be used.