Skip to content
Related Articles
Open in App
Not now

Related Articles

Difference between Statement and CallableStatement

Improve Article
Save Article
Like Article
  • Last Updated : 23 Jul, 2020
Improve Article
Save Article
Like Article

1. Statement :
It is used for accessing your database. Statement interface cannot accept parameters and useful when you are using static SQL statements at runtime. If you want to run SQL query only once than this interface is preferred over PreparedStatement.

Example –

//Creating The Statement Object  
Statement GFG = con.createStatement();
//Executing The Statement  

2. CallableStatement :
It is used when you want to use the database stored procedures. CallableStatement can accept runtime input parameters.

Example –

//Creating CallableStatement object 
CallableStatement GFG = con.prepareCall("{call anyProcedure(?, ?, ?)}");
//Use GFG.setter() methods to pass IN parameters
//Use GFG.registerOutParameter() method to register OUT parameters
//Executing the CallableStatement
//Use GFG.getter() methods to retrieve the result 

Difference between Statement and CallableStatement :

It is used when SQL query is to be executed only once.It is used when the stored procedures are to be executed.
You can’t pass the parameters at runtime.You can pass the parameters at runtime.
Used for CREATE, ALTER, DROP statements.Used to execute functions.
Performance is very low.Performance is better than Statement.
Used to execute normal SQL queries.Used to call the stored procedures.
It is base interface.It extends PreparedStatement interface.
It is used for DDL statements.It is used for stored procedures.
We can not used statement for reading binary data..We can used CallableStatement for reading binary data..

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!