Thursday, October 13, 2022

JDBC and JDBC Architecture

JDBC or Java Database Connectivity is a specification from Sun microsystems that provides a standard abstraction (that is API or Protocol) for java applications to communicate with various databases. JDBC along with the database driver is capable of accessing databases and spreadsheets. 

The classes and interfaces of JDBC allows application to send request made by users to the specified database.

Interacting with a database requires efficient database connectivity which can be achieved by using the ODBC(Open database connectivity) driver. This driver is used with JDBC to interact or communicate with various kinds of databases such as Oracle, MS Access, Mysql and SQL server database. JDBC provides the same capabilities as ODBC, allowing Java programs to contain database-independent code.

The JDBC library includes APIs for each of the tasks mentioned below that are commonly associated with database usage.


  • Making a connection to a database.

  • Creating SQL or MySQL statements.

  • Executing SQL or MySQL queries in the database.

  • Viewing & Modifying the resulting records.

JDBC Architecture

The JDBC API supports both two-tier and three-tier processing models for database access but in general, JDBC Architecture consists of two layers −


  • JDBC API − This provides the application-to-JDBC Manager connection.
  • JDBC Driver API − This supports the JDBC Manager-to-Driver Connection.

The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous databases.

The JDBC driver manager ensures that the correct driver is used to access each data source. The driver manager is capable of supporting multiple concurrent drivers connected to multiple heterogeneous databases.

Following is the architectural diagram, which shows the location of the driver manager with respect to the JDBC drivers and the Java application −


Common JDBC Components

The JDBC API provides the following interfaces and
classes −


  • DriverManager − This class manages a list of database drivers. Matches
    connection requests from the java application with the proper database
    driver using communication sub protocol. The first driver that recognizes
    a certain subprotocol under JDBC will be used to establish a database
    Connection.

  • Driver − This interface handles the communications with the database
    server. You will interact directly with Driver objects very rarely.
    Instead, you use DriverManager objects, which manages objects of this
    type. It also abstracts the details associated with working with Driver
    objects.

  • Connection − This interface with all methods for contacting a database.
    The connection object represents communication context, i.e., all
    communication with database is through connection object only.

  • Statement − You use objects created from this interface to submit the
    SQL statements to the database. Some derived interfaces accept parameters
    in addition to executing stored procedures.

  • ResultSet − These objects hold data retrieved from a database after you
    execute an SQL query using Statement objects. It acts as an iterator to
    allow you to move through its data.

  • SQLException − This class handles any errors that occur in a database
    application.

0 comments:

Post a Comment

Data Structures with C++



NET/SET/CS PG



Operating Systems



Computer Networks



JAVA



Design and Analysis of Algorithms



Programming in C++

Top