This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
 
 
subject: Callable statements
 
jQuery in Action, 3rd edition