JDBC Architecture

Leave a Comment

The JDBC architecture consists of two major components : JDBC API and JDBC driver types.

The JDBC API is a set of classes interfaces and exceptions used for establishing connection with data source. This JDBC API is defined in the java.sql and javax.sql packages. We use following core JDBC classes and interfaces that belong to java.sql package.

DriverManager

When Java application needs connection to the database it invokes the DriverManager class. This class then loads JDBC drivers in the memory. The DriverManager also attempts to open a connection with the desired database.

Connection

This is an interface which represents connectivity with the data source. The connection is used for creating the Statement instance.

Statement

This interface is used for representing the SQL statements. Some example of SQL statements are
SELECT * FROM student_table;
UPDATE student_table set name='Neel' where roll_no='1';
DELETE from student_table WHERE roll_no='10';

There are two specified Statement types: PreparedStatement and Callable Statement. The Prepared represents the pre-compiled SQL statements.

For instance:
SELECT * FROM student_table WHERE name=?

The placeholder represented by ? is used in this type of statement. There are special type setter methods that assign the values to the placeholders before the SQL statement is executed.

CallableStatement is represents the stored procedures. These are similar to PreparedStatement. In this type of Statements we can assign the methods for the types of output arguments.

ResultSet

This interface is used to represent the database result set. After using SELECT SQL statement, the information obtained from the database can be displayed using ResultSet.

SQLException

For handling SQL exceptions this interface is used.

0 comments:

Post a Comment