Deepa,
hope this helps you.
JDBC has a standard syntax for executing stored procedures, which takes one of two forms:
{call procedurename param1, param2, param3 ... }
{?= call procedurename param1, param2, param3 ... }
The parameters are optional. If your procedure doesn�t take any parameters, the call might look like this:
{call myprocedure}
If your stored procedure returns a value, use the form that starts with ?=. You can also use ? for any of
the parameter values in the stored procedure call and set them just like you set parameters in a
PreparedStatement. In fact, the CallableStatement interface extends the PreparedStatement
interface.
Some stored procedures have a notion of "out parameters," in which you pass a parameter in, the
procedure changes the value of the parameter, and you need to examine the new value. If you need to
retrieve the value of a parameter, you must tell the CallableStatement interface ahead of time by
calling registerOutParameter:
public void registerOutParameter(int whichParameter, int sqlType)
public void registerOutParameter(int whichParameter, int sqlType,
int scale)
public void registerOutParameter(int whichParameter, int sqlType,
String typeName)
After you execute your stored procedure, you can retrieve the values of the out parameters by calling
one of the many get methods. As with the set methods, the parameter numbers on the get methods are
numbered starting from 1 and not 0. For example, suppose you have a stored procedure called
findPopularName that searches the Person table for the most popular first name. Suppose, furthermore,
that the stored procedure has a single out parameter that is the most popular name. You invoke the
procedure this way:
CallableStatement cstmt = myConnection.prepareCall(
"{call findPopularName ?}");
cstmt.registerOutParameter(1, Types.VARCHAR);
cstmt.execute();
System.out.println("The most popular name is "+
cstmt.getString(1));