Open In App

Difference between Statement and CallableStatement

Last Updated : 23 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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  
GFG.executeUpdate("CREATE TABLE STUDENT(ID NUMBER NOT NULL, NAME VARCHAR)"); 

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
 GFG.execute();
 
//Use GFG.getter() methods to retrieve the result 



Difference between Statement and CallableStatement :

Statement 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..


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads