Techniques For Testing A Java Routine - IBM DB2 Manual

Table of Contents

Advertisement

package s1;
import sqlj.runtime.*;
import java.sql.*;
import java.math.*;
#sql iterator NameSal(String LastName, BigDecimal Salary);
public class S1Sal
{
}
Figure 53. Java stored procedure that returns a result set
Notes to Figure 53:
1
2
3
4
5

Techniques for testing a Java routine

The most common techniques for testing a Java routine are testing the routine as a
stand-alone program, using the DB2 Unified Debugger, enabling collection of DB2
debug information, and testing the routine as a stand-alone program, and writing
your own debug information from your routine.
public static void getSals(BigDecimal[] AvgSalParm,
throws SQLException
{
NameSal iter1;
try
{
#sql iter1 = {SELECT LASTNAME, SALARY FROM EMP
WHERE SALARY>0 ORDER BY SALARY DESC};
#sql {SELECT AVG(SALARY) INTO :(AvgSalParm[0]) FROM EMP};
}
catch (SQLException e)
{
System.out.println("SQLCODE returned: " + e.getErrorCode());
throw(e);
}
rs[0] = iter1.getResultSet();
}
This SQLJ clause declares the iterator named NameSal, which is used to retrieve
the rows that will be returned to the stored procedure caller in a result set.
The declaration for the stored procedure method contains declarations for a single
passed parameter, followed by the declaration for the result set object.
This SQLJ clause executes the SELECT to obtain the rows for the result set,
constructs an iterator object that contains those rows, and assigns the iterator
object to variable iter1.
This SQLJ clause retrieves a value into the parameter that is returned to the stored
procedure caller.
This statement uses the getResultSet method to assign the contents of the iterator
to the result set that is returned to the caller.
Related concepts
"Differences between Java routines and other routines" on page 176
"Retrieving multiple result sets from a stored procedure in an SQLJ
application" on page 134
Related tasks
"Retrieving multiple result sets from a stored procedure in a JDBC application"
on page 46
java.sql.ResultSet[] rs)
Chapter 5. Java stored procedures and user-defined functions
1
2
3
4
5
179

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents