---
title: "Callable Statement in Java"  
description: "In Java, CallableStatement is used to call the stored procedures and functions by using an object of the CallableStatement Interface."  
author: "Anupam Mishra"  
published: 2015-11-06  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/11903/callable-statement-in-java  
category: "java"  
tags: ["database", "java", "j2ee", "database design", "database connection", "database schema", "database table"]  
reading_time: 1 minute  

---

# Callable Statement in Java

##### The Broad –level steps to use CallableStatement in an application are as follow:

##### \
1. Creating the CallableStatement object.

##### \
2. Setting the values of parameters.

##### \
3. Registering the OUT parameter type.

##### \
4. Executing the stored procedure or function.

##### \
5. Retrieving the parameter values.

For Example: We have created two table (‘bank’ and ‘personal_details) in [Oracle Database](https://www.mindstick.com/articles/44637/an-insight-into-oracle-database-12c-rdbms).Now, We want to create the [procedure](https://www.mindstick.com/blog/304484/explain-the-sql-stored-procedures) createAccount that can [insert](https://www.mindstick.com/articles/81/insert-update-delete-records-in-csharp-dot-net) a [records](https://www.mindstick.com/forum/34640/how-to-create-a-stored-procedure-for-display-all-records) into both the tables .

\

![Callable Statement in Java](https://www.mindstick.com/mindstickarticle/95b32286-b188-47f0-b3fd-895d8e802dc2/images/2dd667ff-56cd-4b86-b687-03d1949f15ab.png)

\

Now, we used this procedure in java program with the help of JDBC . We create a java file and write code are as follow:

```
import java.sql.*;
/**
* @author Anupam Mishra
*/
public class CallableStatementEx{
public static void main(String args[]) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con=
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
//Step 1: get CallableStatement
CallableStatement cs= con.prepareCall("{call
createaccount(?,?,?,?,?,?)}");
//Step 2:set IN Parameters
cs.setInt(1,1001);
cs.setInt(2,10);
cs.setString(3,"Anupam");
cs.setDouble(4,10000);
cs.setString(5,"Allahabad");
cs.setInt(6,51663);
//Step 3: register OUT parameters
// In this program, we don't have OUT parameters
//Step 4:
cs.execute();
System.out.println("Account Created
Succesfully!..");
con.close();
}
}
```

##### The Output is shown Below:

\

![Callable Statement in Java](https://www.mindstick.com/mindstickarticle/95b32286-b188-47f0-b3fd-895d8e802dc2/images/c665ebad-75bc-4d3a-a2f2-83169944a6fc.png)\

---

Original Source: https://www.mindstick.com/articles/11903/callable-statement-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
