Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Callable statements

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic