What is JDBC?

JDBC(Java Database Connectivity) provides a standard Java API (Application Programming Interface) for accessing different database systems. JDBC provides a simple, database-independent set of APIs. Using the same APIs we can access a number of database systems in Java.

Components of JDBC

1) Driver

For connecting to the database we need to have a suitable Driver class. This Driver class helps us to get the Connection to the corresponding database. Driver class for different database is different and this class knows how to get a Connection from that particular database.

For example the driver class for getting connection to Mysql database is – com.mysql.jdbc.Driver
The driver class for getting connection to Oracle database is – oracle.jdbc.driver.OracleDriver

2) DriverManager

The DriverManager manages a list of database Drivers. The DriverManager will use a suitable Driver class to get a connection from the database. We need to provide database url, username and password to the DriverManager to get a Connection.

3) Connection

This interface provides methods to access database for creating Statements, commit & rollback transactions, fetch metadata etc.

4) Statement/PreparedStatement/CallableStatement

Statement
This interface provides methods for sending SQL statements without parameters to the database.

PreparedStatement
This interface provides methods for sending parameterized SQL statements to the database.

CallableStatement
This interface provides methods for calling database stored procedures. The CallableStatement provides methods for setting up its IN and OUT parameters, and methods for executing the call to a stored procedure.

5) ResultSet

It represents the result of executing a database query using Statement. It provides methods for iterating over the rows in the ResultSet. It also provides methods for retrieving column values from the current row using either the index number of the column or the name of the column.

6) SQLException

An exception that provides information about error while accessing database or other errors.

Leave a Reply

Your email address will not be published. Required fields are marked *