Contents
What is JDBC?
JDBC stands for Java Database Connectivity, is a standard API provided by Java for connecting with databases irrespective of the database vendor. It provides database independent connectivity between the Java program and the database.
The JDBC API consists of different classes and interfaces to perform the following tasks:
- Establish a connection to the database
- Creating SQL statements
- Executing SQL statements
- Displaying and modifying the records in the database
Applications of JDBC
JDBC API can be used for connecting with databases and perform various operations on the data stored in the database. We can JDBC to create different types of Java programs like:
- Java applications (console-based or GUI-based)
- Java applets
- Java servlets
- Java Server Pages (JSPs)
- Enterprise Java Beans (EJBs)
JDBC classes and interfaces
Following is a list of commonly used classes and interfaces available in JDBC API:
Class/Interface | Description |
DriverManager | A class used to load a SQL driver and connect with a database |
Connection | An interface used to make a connection with a database using database credentials |
Statement | An interface used to build a query and submit to the database |
PreparedStatement | An interface used to build a query with placeholders |
CallableStatement | An interface used to call stored procedures or functions in a database |
ResultSet | An interface that represents the resultant data of the SQL statement execution on a database |
ResultSetMetaData | An interface that represents the meta data of the result set |
JDBC architecture
JDBC supports two types of architectures:
- Two-tier architecture
- Three-tier architecture
Two-tier JDBC architecture
A Java application (console, GUI or a web application) communicates directly with the data source or database in two-tier architecture. The user commands or SQL queries are sent to the database and the results will be sent back from the database to the user. A client-server architecture is the best example for two-tier architecture.
The client/user machine will run the Java application from which the queries are sent to the server. The JDBC API on the client manages the SQL queries. On the server, which also contains the database, receives the queries and process them. The results are sent back from the server to the client. The two-tier architecture can be represented as shown below:
Three-tier JDBC architecture
The three-tier architecture adds a middle-tier or also called middleware in between the client tier and the server tier. The middle-tier is often used by organizations for improving the performance of the applications. In three-tier architecture the client sends queries to the middle-tier.
The JDBC API on the middle-tier forwards these queries to the server and finally the results from the server reaches the client through the middle-tier. The middle-tier is often an application server. The three-tier architecture can be represented as shown below:
For more information on JDBC, refer the following links:
Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.
He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.
He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.
Leave a Reply