Example: Returning Two Result Sets - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantage™

Here is an example of a method that returns two result sets:

/**************************************************************
   DDL for the Java external stored procedure:

   REPLACE PROCEDURE UsrCmd(  Command VARCHAR(120) )
      LANGUAGE JAVA 
      READS SQL DATA
      PARAMETER STYLE JAVA
      DYNAMIC RESULT SETS 2
      EXTERNAL NAME 'jUdfRs:jUdfRsExamples.UsrCmd';

 **************************************************************/

public class jUdfRsExamples {
   public static void UsrCmd(String Command,
                             ResultSet[] rs1,
                             ResultSet[] rs2) throws SQLException {
      Connection con = 
         DriverManager.getConnection( "jdbc:default:connection" );
      Statement stmt =          con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
            ResultSet.CONCUR_READ_ONLY);

      /* Execute user's command. */
      if (stmt.execute( Command )) {
         /* Return the result set. */
         rs1[0] = stmt.getResultSet();
      }
      if ( stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT)) {
         /* Get a second result set if needed. */
         rs2[0] = stmt.getResultSet();
      }
   }
   ...
}