Scalable Database Server, HiRDB Version 8 UAP Development Guide

[Contents][Index][Back][Next]

9.4.4 Results-set return facility (Java stored procedures only)

You can use the results-set return facility by specifying 1 or a greater value in the DYNAMIC RESULT SETS clause in CREATE PROCEDURE during Java stored procedure definition. The results-set return facility is not supported for Java stored functions.

Organization of this subsection
(1) What is the results-set return facility?
(2) Calling-source languages supporting the results-set return facility
(3) Example of using the results-set return facility
(4) Notes about using the results-set return facility

(1) What is the results-set return facility?

The results-set return facility enables the Java stored procedure caller to reference the cursor that is acquired by the execution of the SELECT statement within the Java stored procedure.

Figure 9-11 shows an overview of the results-set return facility.

Figure 9-11 Overview of the results-set return facility (for a Java stored procedure)

[Figure]

(2) Calling-source languages supporting the results-set return facility

The calling-source languages that support the results-set return facility are as follows:

* COBOL can be used if the RDB file input/output facility is not used.

(3) Example of using the results-set return facility

This example obtains columns rank, name, and age, which satisfy condition rank<10 in tables emps_1 and emps_2 within a Java stored procedure. The caller receives two result sets to manipulate them.

Explanation
  1. Defines the procedure name and parameters.
  2. Specifies the number of retrieval result sets to be returned.
  3. Specifies LANGUAGE.
  4. Associates with the Java method.
  5. Specifies PARAMETER STYLE.

Explanation
  1. Imports the java.sql package.
  2. Defines the class name.
  3. Defines the method name.
  4. Defines the parameter name (the second and third arguments are for returning result sets).
  5. Obtains the Connection object.
  6. Preprocesses the SELECT statement.
  7. Executes the SELECT statement.
  8. Sets the obtained result set rs1 in the second argument of the ResultSet[] type.
  9. Preprocesses the SELECT statement.
  10. Executes the SELECT statement.
  11. Sets the obtained result set rs1 in the third argument of the ResultSet[] type.
  12. Terminates the call and returns the result sets.

Explanation
  1. Imports the java.sql package.
  2. Defines the class name.
  3. Defines the method name.
  4. Obtains the Connection object.
  5. Preprocesses the CALL statement.
  6. Declares variables.
  7. Executes the CALL statement.
  8. Obtains the result set.
  9. Outputs information obtained from the first result set.
  10. Checks to see if there are any more result sets.
  11. Obtains the next result set.
  12. Outputs information obtained from the second result set.
  13. Closes the result sets.

(4) Notes about using the results-set return facility

(a) When defining a Java stored procedure with CREATE PROCEDURE
  1. In the DYNAMIC RESULT SETS clause, specify the maximum number of result sets to be returned from within the Java stored procedure. If a value of 0 is specified, the system does not use the results-set return facility.
  2. For a parameter in CREATE PROCEDURE, do not specify the OUT parameter of ResultSet[] type that is specified for a parameter in the Java stored procedure.
  3. When using EXTERNAL NAME to define correspondence with a Java program, include arguments of the ResultSet[] type.
(b) When creating a caller's method
  1. In the CALL statement's parameters, do not include a parameter of the ResultSet[] type in the method for Java stored procedure.
  2. If there is more than one result set to be returned, to receive the second or subsequent result set, use the getMoreResult method (to determine whether there are more result sets) and the getResultSet method (to receive the next result).
(c) When creating a method for a Java stored procedure

Specify the retrieval result (ResultSet) in the OUT parameter of the ResultSet[] type without closing it.