Recent Posts
- NCC Punjab LDC Results 2013 NCCPunjab.com Interview Selected Candidates List
- RGUHS PGSSET Super Speciality 2013 Exam www.logisys.net.in Online Application
- RKCL RS-CIT Results 2013 rkcl.in RSCIT Final Exam May Result 2013
- TNEB Electricity Bills Online Payment tnebnet.org/awp/login Tamilnadu EB Payment System
- Kerala LET 2013 Fee Structure for 2013-14 Engineering College Admission
Discussion Forum
Callable Statements in Java With Example
Callable Statements in Java With Example. This Java Callable Statements example describes the basic operations performed on the JDBC Callable Statements database connectivity code.
Callable Statements in Java With Example. This Java Callable Statements example describes the basic operations performed on the JDBC Callable Statements database connectivity code.In this example you will learn about how to write java code for Callable Statements with oracle database.
Program:
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;
public class CallableStmtDemo {
public static void main(String args[]){
Connection con=null;
CallableStatement cst = null;
try {
Class.forName(“oracle.jdbc.driver.OracleDriver”);
con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:ORCL”,”scott”,”tiger”);
cst = con.prepareCall(“{?=call addfun(?,?)}”);
cst.setInt(2,10);
cst.setInt(3,20);
cst.registerOutParameter(1, Types.INTEGER);
cst.execute();
int result = cst.getInt(1);
System.out.print(“add: “+result);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Stored procedure in oracle:
1 create or replace function addfun(a number,b number)
2 return number is c number(6);
3 begin
4 c:=a+b;
5 return c;
6 end;
