What are the main classes and interfaces of JDBC?

Java 8ProgrammingObject Oriented Programming

JDBC API is available in two packages java.sql, core API and javax.sql JDBC optional packages. Following are the important classes and interfaces of JDBC.

DriverManagerThis class manages the JDBC drivers. You need to register your drivers to this.
It provides methods such as registerDriver() and getConnection().
DriverThis interface is the Base interface for every driver class i.e. If you want to create a JDBC Driver of your own you need to implement this interface. If you load a Driver class (implementation of this interface), it will create an instance of itself and register with the driver manager.
StatementThis interface represents a static SQL statement. Using the Statement object and its methods, you can execute an SQL statement and get the results of it.
It provides methods such as execute(), executeBatch(), executeUpdate() etc. To execute the statements.
PreparedStatementThis represents a precompiled SQL statement. An SQL statement is compiled and stored in a prepared statement and you can later execute this multiple times. You can get an object of this interface using the method of the Connection interface named prepareStatement(). This provides methods such as executeQuery(), executeUpdate(), and execute() to execute the prepared statements and getXXX(), setXXX() (where XXX is the datatypes such as long int float etc..) methods to set and get the values of the bind variables of the prepared statement.
CallableStatementUsing an object of this interface you can execute the stored procedures. This returns single or multiple results. It will accept input parameters too. You can create a CallableStatement using the prepareCall() method of the Connection interface.
Just like Prepared statement, this will also provide setXXX() and getXXX() methods to pass the input parameters and to get the output parameters of the procedures.
ConnectionThis interface represents the connection with a specific database. SQL statements are executed in the context of a connection.
This interface provides methods such as close(), commit(), rollback(), createStatement(), prepareCall(), prepareStatement(), setAutoCommit() setSavepoint() etc.
ResultSetThis interface represents the database result set, a table which is generated by executing statements. This interface provides getter and update methods to retrieve and update its contents respectively.
ResultSetMetaDataThis interface is used to get the information about the result set such as, number of columns, name of the column, data type of the column, schema of the result set, table name, etc
It provides methods such as getColumnCount(), getColumnName(), getColumnType(), getTableName(), getSchemaName() etc.
Published on 19-Mar-2019 17:05:09