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


Similar Reads

Difference between PreparedStatement and CallableStatement
1. 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
2 min read
Difference between Row level and Statement level triggers
Triggers are defined as stored programs which are automatically executed whenever some events such as CREATE, ALTER, UPDATE, INSERT, DELETE takes place.They can be defined on a database, table, view with which event is associated. Triggers can be broadly classified into Row Level and Statement Level triggers. Broadly, these can be differentiated as
1 min read
Difference between Statement and PreparedStatement
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 then this interface is preferred over PreparedStatement. Example - //Creating The Statement Object Statement prep_statement = con.createStatement()
2 min read
Difference between Control Structure and Control Statement
1. Control Structure :Control Structure, as name suggests, is basically a set of statements and control statements that are controlling their execution. 2. Control Statement :Control Statement, as name suggests, is basically a statement that is used to determine control flow of set of statements. It makes decision on basis of condition provided by
2 min read
Difference between break and continue statement in C
In this article, we will discuss the difference between the break and continue statements in C. They are the same type of statements which is used to alter the flow of a program still they have some difference between them. break statement: This statement terminates the smallest enclosing loop (i.e., while, do-while, for loop, or switch statement).
3 min read
CREATE and DROP INDEX Statement in SQL
The CREATE INDEX statement will create indexes in tables. Indexes are used for data procurement from the databases faster. The users cannot see the indexes, they are running in the background of queries, used to speed up searches/queries. Create an index on a table : Syntax: CREATE INDEX indexname ON tablename (columnname1, columnname2, ...); Creat
2 min read
Delete statement in MS SQL Server
A database contains many tables that have data stored in order. To delete the rows, the user needs to use a delete statement. 1. To DELETE a single record : Syntax - DELETE FROM table_name WHERE condition; Note - Take care when deleting records from a table. Note that the WHERE clause in the DELETE statement. This WHERE specifies which record(s) ne
2 min read
Reverse Statement Word by Word in SQL server
To reverse any statement Word by Word in SQL server we could use the SUBSTRING function which allows us to extract and display the part of a string. Pre-requisite :SUBSTRING function Approach : Declared three variables (@Input, @Output, @Length) using the DECLARE statement. Use the WHILE Loop to iterate every character present in the @Input. For th
2 min read
Insert Into Select statement in MS SQL Server
Prerequisites - Insert statement in MS SQL Server, Select statement in MS SQL Server Consider a university database. There are two tables namely Student and Marks. In case, the marks of a few students has to be transferred from the marks table to the marks table, there are many ways to do so. One can use subqueries (query nested in another query) b
2 min read
Difference between Difference Engine and Analytical Engine
Introduction: The development of computing technology has a rich history, with many inventions and innovations leading to the creation of the modern computer. Two such machines, the Difference Engine and Analytical Engine, were created by the English mathematician and inventor Charles Babbage in the 19th century. While these machines share some sim
7 min read
Article Tags :