Friday, 20 January 2017

CALLABLESTATEMENT

CallableStatement is a subtype of PreparedStatement. CallableStatement is an interface. This interface is implemented by JDBC driver developers. CallableStatement is used to call stored procedures or functions.


How to create CallableStatement object

  • Connection provide the following method which return CallableStatement object.
  • CallableStatement prepareCall(String sql) - creates a CallableStatement object for calling database stored procedures.

What is the difference between Statement, PreparedStatement and CallableStatement

Statement - It is used for sending SQL statements to database. It is used to send static SQL statements. It is without parameters. SQL statements is compiled every-time before execution. SQL injection problem is present in Statement.

PreparedStatement - It is used for sending SQL statement to database. It is used to send dynamic SQL statement. PreparedStatement is with parameter. SQL statement is compiled and stored in PreparedStatement object. It avoids SQL injection problem.

CallableStatement - It is used to call stored procedure and functions. It is used to call pre-compiled procedures or functions exist in database. It is with parameter. Call to procedure is compiled only once and stored in CallableStatement object. Avoid SQL injection problem.


No comments:

Post a Comment