JDBC Callable Statement Example

JDBC Callable Statement Theory

  • CallableStatement interface is used to call the stored procedures or functions.
  • We can have business logic on the database by the use of stored procedures and functions that will make the performance better because they are precompiled.
  • For example we need to retrieve the age of the student based on birth date, one may create a function that receives date as INPUT and returns age of the student as the OUTPUT.

JDBC Prepared Statement Example

  • The main feature of a PreparedStatement object is that, unlike a Statement object, it is given a SQL statement when it is created.
  • The advantage to this is that in most cases, this SQL statement is sent to the DBMS right away, where it is compiled.
  • As a result, the PreparedStatement object contains not just a SQL statement, but a SQL statement that has been precompiled.
  • This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement SQL statement without having to compile it first.

What is JDBC Prepared Statement?

  • Sometimes it is more convenient to use a PreparedStatement object for sending SQL statements to the database. This special type of statement is derived from the more general class, Statement, that you already know.
  • If you want to execute a Statement object many times, it usually reduces execution time to use a PreparedStatement object instead.
%d bloggers like this: