J F W

making web application programming easier is possible

HOW TO : CORE

execute a stored procedure

In this example will see how to execute a stored procedure. We suppose that we have a stored procedure with name  mysp and the package of the stored procedure is mypackage.

The name of the class used to execute the stored procedure is MySP. Here is the code:

Our class extends StoredProcedureGateway. This class has two abstract methods that our class must implement.

In our example, we use the default database resource: if a different resource have to be used, then the relative constructor of StoredProcedureGateway must be called. For example, if we want to use the resource with name db2 then we have to substitute the code in the constructor with this one:

If the execution of the stored procedure is part of a transaction, then we have to implement a constructor that can take the Transaction parameter and the relative constructor of StoredProcedureGateway must be called:

The method setStoredProcedure is used to set the stored procedure:

If our stored procedure has input and/or output parameters they must be declared before the execution of the stored procedure. To set the input parameters we use the method setInput:

In our example the first two parameters are of type in, the first one is an integer and the second a string.

To set the output parameters we use the method setOutput:

The first of the output parameters is an integer and the second a string.

The method myExecute is used for executing the stored procedure and eventually reading the returned data and/or the output parameters:

The boolean parameter of method execute is true when the stored procedure returns a result set (cursor). In that case the data returned will be read automatically by the method and will be saved in outputdata under the key ALL_ROWS_KEY.
Under the key RESULT_KEY will be saved a boolean with value true if no error occur or false in the other case.
The output parameters must be read explicitly using the callable statement.

To call the MySP class from an action we have to write: