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
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
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.
This interface provides methods to access database for creating Statements, commit & rollback transactions, fetch metadata etc.
This interface provides methods for sending SQL statements without parameters to the database.
This interface provides methods for sending parameterized SQL statements to the database.
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.
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.
An exception that provides information about error while accessing database or other errors.