Before performing any operations in JDBC, we need to establish a connection to the database. Here are some of the important classes/interfaces in JDBC for executing SQL statements:
JDBC class/interface |
Description |
java.sql.Connection |
Represents the connection between the application and the backend database. Must for performing any action on the database. |
java.sql.DriverManager |
Manages JDBC drivers used in the application. Call the DriverManager.getConnection static method to obtain the connection. |
java.sql.Statement |
Used for executing static SQL statements. |
java.sql.PreparedStatement |
Used for preparing parameterized SQL statements. SQL statements are pre-compiled and can be executed repeatedly with different parameters. |
Java.sqlCallableStatement |
Used for executing a stored procedure. |
java.sql.ResultSet |
Represents a row in the database table in the result returned after execution of an SQL query by Statement or PreparedStatement. |
Many of these are interfaces, and implementations of these interfaces are provided by the JDBC drivers.