EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

JDBC Architecture

By Priya PedamkarPriya Pedamkar

Secondary Sidebar
Database Management Tutorial
  • DataBase Management
    • Text Data Mining
    • Roles of Database Management System in Industry
    • SQL Server Database Management Tools
    • Databricks CLI
    • Database administrator skills
    • Database Management Systems Advantages
    • Database Testing Interview Questions
    • Netezza Database
    • Data Administrator
    • Database Administrator
    • Data manipulation
    • Database Management Software
    • DataStage
    • Types of Database Models
    • Types of Database
    • Hierarchical Database Model
    • Relational Database
    • Relational Database Advantages
    • Operational Database
    • What is RDBMS?
    • Data Masking Tools
    • Database Security
    • Data Replication
    • Bitmap Indexing
    • Second Normal Form
    • Third Normal Form
    • Fourth Normal Form
    • Data Definition Language
    • Data Manipulation Language
    • Data Control Language
    • Transaction Control Language
    • Dataset Normalization
    • jdbc connection
    • Conceptual Data Model
    • Entity-Relationship Model
    • Relational Database Model
    • Sequential File Organization
    • Teradata Create Table
    • Teradata Database
    • Centralized Database
    • Data Storage in Database
    • Thomas write Rule
    • DBA Interview Questions
    • What is JDBC?
    • jdbc hive
    • Apriori Algorithm
    • JDBC Architecture
    • JDBC Interview Questions
    • Datastage Interview Questions
    • Wildcard Characters
    • Distributed Database System
    • Multidimensional Database
  • TSQL Basic
    • TSQL
    • What is T-SQL
    • T-SQL Commands
    • T-SQL String Functions
    • TSQL Interview Questions

Related Courses

SQL Certification Course

PL/SQL Certification Course

Oracle Certification Course

Home Data Science Data Science Tutorials Database Management Tutorial JDBC Architecture

JDBC Architecture

Introduction to JDBC Architecture

Java Database Connectivity (JDBC) is an API (Application Program Interface) or platform-independent interface which helps to connect java programs with various databases such as Oracle, My SQL, MS Access and SQL Server. It provides ways to query and update the database using Structured Query Language (SQL) update statements such as CREATE, DELETE, INSERT and UPDATE and query statements like SELECT. It is almost similar to ODBC (Open Database Connectivity) that was provided by Microsoft.

To connect the java program or application with the database there are five steps to be followed:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)

1. Load the Driver: Driver helps to make a connection to the database hence driver must be loaded once in the program. This can be done by two methods:

  • Class.forName(): By using this, the driver’s class file is loaded in the memory during run time. There is no need to create a new object. For example:

Class.forName(“oracle.jdbc.driver.OracleDriver”);

  • DriverManager.registerDriver(): Here DriverManager is an inbuilt Java class where the register is its static member. By using this, the constructor of the driver class is called during compile time. In this new object is created. For example:

DriverManager.registerDriver(new oracle.jdbd.driver.OracleDriver());

2. Creating Connections: After the driver is loaded, the connection is set up. The connection object uses username, password, and URL to set up the connection. URL has a predefined format which contains database name, the driver used, IP address where the database is stored, Port number and the service provider. The connection can be set up by using the command:

Connection con = DriverManager.getConnection(URL, user, password);

3. Creating Statement: After establishing the connection, the user can interact with the database. The interfaces such as JDBC statement, PreparedStatement, CallableStatement provides methods that allow a user to send SQL statements and get data from the database. Command used to create statement is;

Statement stmt = con.createStatement();

4. Executing Query: The SQL query is executed to interact with the database. A query can be for updating/inserting in the database or for retrieving data. Statement interface provides two methods i.e. executeQuery() method to execute queries for retrieving data while executeUpdate() method to execute queries for updating or inserting. For Example:

int n = stmt.executeUpdate(“DELETE TABLENAME”);
if(n==1)
System.out.println(“Success”);
else
System.out.println(“Failed”);

5. Closing Connection: After executing our query, the data user wanted to update or retrieve has been done so now it’s time to close the established connection. The connection interface provides a method close() to close the connection. For example:

con.close();

JDBC Architecture

JDBC supports two types of processing models for accessing database i.e. two-tier and three-tier.

1. Two-tier Architecture

This architecture helps java program or application to directly communicate with the database. It needs a JDBC driver to communicate with a specific database. Query or request is sent by the user to the database and results are received back by the user. The database may be present on the same machine or any remote machine connected via a network. This approach is called client-server architecture or configuration.

2. Three-tier Architecture

In this, there is no direct communication. Requests are sent to the middle tier i.e. HTML browser sends a request to java application which is then further sent to the database. Database processes the request and sends the result back to the middle tier which then communicates with the user. It increases the performance and simplifies the application deployment.

two -Three – tier Architecture

Components of JDBC Architecture

The components are explained below.

  • Driver Manager: It is a class that contains a list of all drivers. When a connection request is received, it matches the request with the appropriate database driver using a protocol called communication sub-protocol. The driver that matches is used to establish a connection.
  • Driver: It is an interface which controls the communication with the database server. DriverManager objects are used to perform communication.
  • Connection: It is an interface which contains methods to contact a database.
  • Statement: This interface creates an object to submit SQL queries or statements to the database.
  • ResultSet: This contains the results retrieved after the execution of the SQL statements or queries.
  • SQLException: Any errors that occur in database application are handled by this class.

Basic JDBC architectural diagram is shown below with the positioning of all components:

JDBC Architecture

Interfaces

The java.sql package consists of many interfaces. Some popular interfaces are mentioned below:

  • Driver Interface: This interface allows for multiple database drivers. DriverManager objects are created to communicate with the database. These objects are created by DriverManager.registerDriver();
  • Connection Interface: Connection interface establishes the connection i.e. session between java program and the database. It has many methods like rollback(), close() etc.
  • Statement Interface: This interface provides methods for the execution of the SQL queries. It provides factory methods to get a ResultSet object. Some methods of statement interface are executeQuery(), executeUpdate() etc.
  • PreparedStatement Interface: This interface helps when the SQL queries need to implement many times. It accepts input parameters during runtime.
  • CallableStatement Interface: This interface is used when stored procedures are to be accessed. It also accepts parameters during run time.
  • ResultSet Interface: This interface helps to store the result returned after the execution of the SQL queries.

Types of JDBC drivers

There are four types of JDBC drivers:

1. Type-1 Driver or JDBC-ODBC Bridge

This driver acts as a bridge between JDBC and ODBC. It converts JDBC calls into ODBC calls and then sends the request to ODBC driver. It is easy to use but execution time is slow.

JDBC-ODBC Bridge

2. Type-2 Driver or Native API Partly Java Driver

This driver uses JNI (Java Native Interface) call on database specific native client API. It is comparatively faster than Type-1 driver but it requires native library and cost of application also increases.

Native API Partly Java Driver

3. Type-3 Driver or Network Protocol Driver

These drivers communicate to JDBC middleware server using proprietary network protocol. This middleware translates the network protocol to database specific calls. They are database independent. They can switch from one database to another but are slow due to many network calls.

Network Protocol Driver

4. Type-4 or Thin Driver

This driver is also called pure Java driver because they directly interact with the database. It neither requires any native library nor middleware server. It has better performance than other drivers but comparatively slow due to an increase in a number of network calls.

Thin Driver

Conclusion

This article specifies the JDBC architecture, its interfaces and types of drivers to communicate or interact with the database.

Now a day’s databases are maintained in every sector hence updating them and retrieving data from them is necessary. So understanding the architecture would help to understand the basic JDBC concepts.

Recommended Articles

This has been a guide to JDBC Architecture. Here we discussed the types of drivers, interfaces, and Components of JDBC Architecture. You can also go through our other suggested articles to learn more –

  1. How to Install Java 8?
  2. JDBC Interview Questions
  3. How To Install Apache?
  4. JDBC Driver
Popular Course in this category
JDBC Training (6 Courses, 7+ Projects)
  6 Online Courses |  7 Hands-on Projects |  37+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

SQL Training Program (7 Courses, 8+ Projects)4.9
PL SQL Training (4 Courses, 2+ Projects)4.8
Oracle Training (14 Courses, 8+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - JDBC Training(6 Courses, 7+ Projects) Learn More