aspose file tools*
The moose likes JDBC and the fly likes Callable statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Callable statements" Watch "Callable statements" New topic
Author

Callable statements

Anonymous
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
Sheriff

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
try
{
//create the callable statement objects
CallableStatement oracleProcedure = conn.prepareCall("begin"
+ " Oracle_Procedure_name" + "(?,?,?); end;");
//register the in and out parameters
oracleProcedure.setxxx(1, order);
oracleProcedure.registerOutParameter(2, Types.xxx);
oracleProcedure.registerOutParameter(3, Types.xxx);
//execute the procedure
oracleProcedure.execute();
//get the return values
returnValue2 = oracleProcedure.getxxx(2);
returnValue3 = oracleProcedure.getxxx(3);
oracleProcedure.close();
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
 
jQuery in Action, 2nd edition
 
subject: Callable statements