What Are The Types of Statements in JDBC

the JDBC API has 3 Interfaces, (1. Statement, 2. PreparedStatement, 3. CallableStatement ). The key features of these are as follows: Statement

  • This interface is used for executing a static SQL statement and returning the results it produces.
  • The object of Statement class can be created using Connection.createStatement() method.
  • PreparedStatement
  • A SQL statement is pre-compiled and stored in a PreparedStatement object.
  • This object can then be used to efficiently execute this statement multiple times.
  • The object of PreparedStatement class can be created using Connection.prepareStatement() method. This extends Statement interface.
  • CallableStatement
  • This interface is used to execute SQL stored procedures.
  • This extends PreparedStatement interface.
  • The object of CallableStatement class can be created using Connection.prepareCall() method.

Statement: to be used createStatement() method for executing single SQL statement

PreparedStatement: To be used preparedStatement() method for executing same SQL statement over and over.

CallableStatement: To be used prepareCall() method for multiple SQL statements over and over.