File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Callable statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Callable statements" Watch "Callable statements" New topic

Callable statements

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Pl. can somebody send give me a working example of a callable statement in JDBC.
The callable statement will execute an Oracle procedure having 1 OUT parameter and 2 IN paramaters
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
Ok this assumes that you have a current Connection Object and the Stored procedure is defined with the first agrument as the IN parameter and the 2nd and 3rd are the OUT parameters
//create the callable statement objects
CallableStatement oracleProcedure = conn.prepareCall("begin"
+ " Oracle_Procedure_name" + "(?,?,?); end;");
//register the in and out parameters
oracleProcedure.setxxx(1, order);
//execute the procedure
//get the return values
returnValue2 = oracleProcedure.getxxx(2);
returnValue3 = oracleProcedure.getxxx(3);
oracleProcedure = null;
catch(SQLException se)
System.out.println("Sql Exception : " + se);
you set the in variable (setxxx) per the sets in java.sql.PreparedStatement such as setInt or setString
now you set the types for the returns per java.sql.Types
such as Types.CHAR
the getxxx methods are defined in java.sql.CallableStatement

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: Callable statements
It's not a secret anymore!