Execute Stored Procedure

Executes an SQL stored procedure by specifying its name and parameter array.

Inputs

Database connection
A CwDBConnection object that represents the database connection.

Stored procedure
A String that represents the stored procedure to execute in the database.

Parameters
A Vector object of arguments to pass to parameters in the SQL query.

Exceptions

The Execute Stored Procedure function block can throw the CwDBSQLException exception if a database error occurs.

Notes

The Execute Stored Procedure function block sends a call to the specified storedProcedure to the database associated with the current connection. This function block sends the stored-procedure call as a prepared SQL statement; that is, the first time it executes, this stored-procedure call is sent as a string to the database, which compiles the string into an executable form (called a prepared statement), executes the SQL statement, and returns this prepared statement to Execute Stored Procedure. The function block then saves this prepared statement in memory.

Important

Before executing a stored procedure with this function block, you must create a CwDBConnection object with the Get Database Connection function block.

To handle any data that the stored procedure returns, use the Has More Rows and Next Row function blocks.

You can also use the Execute SQL, Execute SQL with Parameter, Execute Prepared SQL, or Execute Prepared SQL with Parameter function block to execute a stored procedure as long as this stored procedure does not contain OUT parameters. If the stored procedure uses OUT parameters, you must use the Execute Stored Procedure function block to execute it.

Unlike the group of Execute SQL and Execute Prepared SQL function blocks, the Execute Stored Procedure function block does not require you to pass in the full SQL statement to execute the stored procedure. With Execute Stored Procedure, you need to pass in only the name of the stored procedure and a Vector parameter array of CwDBStoredProcedureParam objects. The Execute Stored Procedure function block can determine the number of parameters from the storedProcParameters array and builds the calling statement for the stored procedure.

Related information

This function block is based on the CwDBConnection.executeStoredProcedure() method. For more information, see executeStoredProcedure().

Copyright IBM Corp. 2004