File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Callable statements
 
Similar Threads
diff between statement , prepare statement , callable statement
start time for a CallableStatement
what is better
Function in Callable Statement
Prepared Statement Vs. Callable Statement