EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #150 background imageLoading...
Page #150 background image
“sqlj.runtime.Scrollable interface” on page 302
Calling stored procedures in an SQLJ application
To call a stored procedure, you use an executable clause that contains an SQL
CALL statement.
You can execute the CALL statement with host identifier parameters. You can
execute the CALL statement with literal parameters only if the DB2 server on
which the CALL statement runs supports execution of the CALL statement
dynamically.
The basic steps in calling a stored procedure are:
1. Assign values to input (IN or INOUT) parameters.
2. Call the stored procedure.
3. Process output (OUT or INOUT) parameters.
4. If the stored procedure returns multiple result sets, retrieve those result sets.
The following code illustrates calling a stored procedure that has three input
parameters and three output parameters. The numbers to the right of selected
statements correspond to the previously-described steps.
Related concepts
“SQL statement execution in SQLJ applications” on page 112
“Retrieving multiple result sets from a stored procedure in an SQLJ
application”
Retrieving multiple result sets from a stored procedure in an
SQLJ application
Some stored procedures return one or more result sets to the calling program. The
calling program needs to retrieve the contents of those result sets.
To retrieve the rows from those result sets, you execute these steps:
1. Acquire an execution context for retrieving the result set from the stored
procedure.
String FirstName="TOM"; // Input parameters 1
String LastName="NARISINST";
String Address="IBM";
int CustNo; // Output parameters
String Mark;
String MarkErrorText;
...
#sql [myConnCtx] {CALL ADD_CUSTOMER(:IN FirstName, 2
:IN LastName,
:IN Address,
:OUT CustNo,
:OUT Mark,
:OUT MarkErrorText)};
// Call the stored procedure
System.out.println("Output parameters from ADD_CUSTOMER call: ");
System.out.println("Customer number for " + LastName + ": " + CustNo); 3
System.out.println(Mark);
If (MarkErrorText != null)
System.out.println(" Error messages:" + MarkErrorText);
Figure 44. Example of calling a stored procedure in an SQLJ application
134 Application Programming Guide and Reference for Java

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability