CallableStatement is an inbuilt interface present in java.sql package. It is used to call stored procedure.
Let’s see an example for better understanding:
Now I have taken a product table like; create table product ( id varchar2(200), name varchar2(200) )
Now I will create a stored procedure named as insertProcedure like create or replace procedure insertProcedure ( id in varchar2, name in varchar2 ) is begin insert into product values(id,name); end /
Now I will develop JDBC program:
packagecom.silan; importjava.sql.*; publicclass JdbcExample5 { publicstaticvoidmain(String[] args) throws Exception{ //To Load and Register the Driver Class.forName("oracle.jdbc.driver.OracleDriver"); //Establish the connection Connectioncon=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); //Create the statement object CallableStatementcs=con.prepareCall("{call insertProcedure(?,?)}"); cs.setInt(1, 102); cs.setString(2, "Fair & Lovely"); //Execute the sql statement cs.execute(); System.out.println("record inserted successfully"); //Close the connection con.close(); } }
Now we will go to the database environment and check the product table by executing following sql statement:
select * from product
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc