Font Awesome Icons

Tutorial

CollableStatement

CallableStatement Interface

To call the stored procedures and functions, CallableStatement interface is used.

to get the instance of CallableStatement

public CallableStatement prepareCall(“{ call procedurename(?,?…?)}”);

Example to get the instance of CallableStatement

CallableStatement stmt=con.prepareCall(“{call myprocedure(?,?)}”);

Example to call the stored procedure using JDBC

To call the stored procedure, we need to create it in the database.

create or replace procedure “INSERTR”  

(id IN NUMBER,  

name IN VARCHAR2)  

is  

begin  

insert into user420 values(id,name);  

end;  

/     

Example:-

import java.sql.*;  

public class Proc 

{  

public static void main(String[] args) throws Exception

{  

  

Class.forName(“oracle.jdbc.driver.OracleDriver”);  

Connection con=DriverManager.getConnection(  

“jdbc:oracle:thin:@localhost:1521:xe”,”system”,”oracle”);  

  

CallableStatement stmt=con.prepareCall(“{call insertR(?,?)}”);  

stmt.setInt(1,1011);  

stmt.setString(2,”Alok”);  

stmt.execute();  

  System.out.println(“success”);  

}  

}  

Hi, Welcome to etechvidya