Using Statement versus PreparedStatement versus CallableStatement

Choose between the Statement, PreparedStatement, and CallableStatement interfaces; it depends on how you plan to use the interface. The Statement interface is optimized for a single execution of an SQL statement, while the PreparedStatement object is optimized for SQL statements that will be executed multiple times, and CallableStatement is generally preferred for executing stored procedures:

  • Statement: The PreparedStatement is used to execute normal SQL queries. It is preferred when a particular SQL query is to be executed only once. The performance of this interface is very low.
  • PreparedStatement: The PreparedStatement interface is used to execute parametrized or dynamic SQL queries. It is preferred when a particular query is to be executed multiple times. The performance of this interface is better than the Statement interface (when used for multiple executions of the same query).
  • CallableStatement: The CallableStatement interface is preferred when the stored procedures are to be executed. The performance of this interface is high.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset