Java JDBC - Introduction

What is JDBC?

JDBC stands for Java Database Connectivity, it is an API for database independent connectivity between Java programs and databases. It helps in connecting wide range of databases and execute the query with the database.

The java.sql package contains classes and interfaces for working with databases. Below is the list of  commonly used classes and interfaces available in java.sql  package :

  • DriverManager class : A list of database drivers is managed by this class, which matches connection requests from java application with the proper database driver using communication sub protocol.   
  • Driver interface : Communication with database is managed by this interface but we will rarely use objects of this interface rather we will be using Objects of DriverManager class for communication with database. 
  • Connection interface : Objects of this interface represents the communication context. Methods available in this interface helps in contacting database. 
  • Statement interface : SQL statements are submitted using objects of this interface.
  • PreparedStatement interface : Parameterized SQL statements are submitted through objects of this interface.  
  • ResultSet interface : Object of this interface will hold the data returned from SQL query execution.
  • ResultSetMetaData interface : Object of this interface holds metadata information about the resultset returned from SQL query execution. 
The JDBC library includes classes and interfaces for performing below tasks :
  1. Making connection to database.
  2. Creating SQL Statements
  3. Executing SQL queries
  4. Viewing and modifying the result set. 
JDBC API uses JDBC drivers to connect with database. There are four types of drivers :
  1. JDBC-ODBC Bridge Driver
  2. Native Driver
  3. Network Protocol Driver
  4. Thin Driver
JDBC Architecture 

JDBC API supports Two-Tier and Three-Tier processing models :

Two-Tier Architecture for Data Access :

JDBC 2Tier processing
In this architecture a Java Applet or Application talks directly to data source. This requires a JDBC driver that can communicate with particular database. A user's command are delivered to the database and result of those commands are send back to the user. The database in this situation may be located on another machine to which user is connected via network. This is referred to as client/server configuration, where user's machine is client and the machine hosting database is called server. 

Three-Tier Architecture for Data Access :

3-tier JDBC Architecture

In three tier architecture commands are send to a middle tier of services which then send those commands to database server. The database server processes those commands and sends results back to middle tier, which then sends those results back to users. 
Share:

Related Posts:

No comments:

Post a Comment

Popular Posts

Recent Posts

Followers

Total Pageviews

5,030