0

我正在尝试从 SQLJ Java 存储过程中接收 ResultSet。客户端没有得到 ResultSet。所以我不知道我创建、传输或接收 ResultSet 是否有任何问题。

这就是我创建过程的方式:

     CREATE PROCEDURE SCHEMA.JOBNAMENGET 
(IN FILTER CHARACTER(8))                
EXTERNAL NAME 'STPDFIDB.JOBNAMENGET      
 (java.lang.String,java.sql.ResultSet[])'
 DYNAMIC RESULT SETS 1                   
 LANGUAGE JAVA                           
 PARAMETER STYLE JAVA                    
 NO COLLID                               
 PACKAGE PATH 'SCHEMA,NULLID'              
 PROGRAM TYPE SUB                        
 WLM ENVIRONMENT XXXXXXXX;  

外部 Java 过程的代码:

import java.sql.*;
import com.ibm.db2.jcc.DB2Connection;
import java.util.Properties;
import sqlj.runtime.ExecutionContext;

#sql iterator Cursor1 (String, String);

public class STPDFIDB {
    #sql static context STPD2FIDB_Ctx;

    public static void JOBNAMENGET (
            String   filter,
            ResultSet[] outRS)throws SQLException {

        Connection conndb2 = null;
        STPD2FIDB_Ctx ctx = null;
        Cursor1 cursor1 = null;
        System.out.println("Vor dem Try");
        try {
            System.out.println("in dem try");

            // Establish Connection; if type-2 z/OS this will trigger load of DLL
            System.out.println ();
            conndb2 = DriverManager.getConnection("jdbc:default:connection" );
            conndb2.setAutoCommit(false);
            ctx  = new STPD2FIDB_Ctx ( conndb2 );

            #sql [ctx] cursor1 = {
                SELECT JOBNAME, KURZBESCHREIBUNG
                    FROM SCHEMA.JOBNAMEN
                    WHERE JOBNAME LIKE :filter
            };
            System.out.print("cursor durchgeführt");


        } catch (SQLException ex) {
            System.err.println("SQLException information");
            System.err.println("Error msg: " + ex.getMessage());
            System.err.println("SQLSTATE: " + ex.getSQLState());
            System.err.println("Error code: " + ex.getErrorCode());
            ex.printStackTrace();
        }
        catch ( Exception e ) {
            System.out.println ( "  ***** ERROR - Unable to load DB2 Universal Driver, " + e );
        }
        outRS[0] = cursor1.getResultSet();
        System.out.println("Whileschleife");
//      
//      while (outRS[0].next()){
//          System.out.println("Jobname = " + outRS[0].getString(1));
//      }


    }
}       

以及来自客户的电话:

  String ergebnis = "";
    ResultSet rs1;

    CallableStatement statement;

    try {           
        // create data source
       com.ibm.db2.jcc.DB2SimpleDataSource ds =  new com.ibm.db2.jcc.DB2SimpleDataSource();

        // set connection properties
        ds.setServerName("XXXXXXXXXXXXXXXXXXXXXXXXXX");
        ds.setPortNumber(XXXX);
        ds.setDatabaseName("XXX");
        ds.setDriverType(4);

        // set trace properties
        ds.setTraceDirectory("c:\\temp");
        ds.setTraceFile("trace");
        ds.setTraceFileAppend(false); 
        ds.setTraceLevel(com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL);

        // get connection
        Properties db2_auth = new Properties();         
        db2_auth.put("user", userName);
        db2_auth.put("password", password);

        Connection con = ds.getConnection(userName, password);


        //Now, issue the CALL statement to invoke the stored procedure

       statement = con.prepareCall("{CALL SCHEMA.JOBNAMENGET(?)}",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);


        statement.setString(1, "BAAAA%%%");

        System.out.println("\nAbout to invoke StProc");

        boolean result = statement.execute();

        rs1 = statement.getResultSet(); 


        while (rs1.next()) {
            System.out.println("In der rs1.next While Schleife");
            System.out.println("Jobname = " + rs1.getString(1));
            System.out.println("Beschr. = " + rs1.getString(2));
        }



            System.out.println("\nJust returned from StProc");


            System.out.println("\nValue returned by stored procedure is " + ergebnis);
            //statement.close();
            //con.close();


        System.out.println("\nInvocation of JAVASPJ was successful!");
       } catch (SQLException e) {
           System.out.println("**SQLException in cjavaspj**");
           System.out.println("Error Message: " + e.getMessage()+ " " + e.getSQLState()+ " " );
       } catch (Exception e) {
           System.out.println("**Non-SQLException in cjavaspj**");
        e.printStackTrace();
       }

    return ergebnis;
}

我已经使用单个字符串作为输出参数测试了连接和 WLM 环境。一切正常。

请有人能告诉我我错过了什么吗?谢谢!

编辑:从存储过程调用之后,WLM 环境说:

Default EBCDIC encoding is 273; as CCSID char: 'Cp273'                        
** Explicit signature provided: '(java.lang.String, java.sql.ResultSetݨ)'    
Generated signature before convert: (Ljava/lang/String;ÝLjava/sql/ResultSet;)V
Processing IN and INOUT parameters of the Java method                         
  parm 1 is String: 'BAAAA%%%' CCSID: 273                                     
Processing dynamic result set parameters of the Java method                   
  parm 2 is of type ÝLjava/sql/ResultSet;                                     
invoking class: STPDFIDB, method: JOBNAMENGET                                 
Back from Call: Processing time was 0.148300                                  
Processing OUT and INOUT parameters of the Java method                        
Processing dynamic result set parameters of the Java method                   
  parm 2 is a dynamic result set, partial description:                        
    Package name: 'STPDFIDB'                                                  
    Collection name: ''                                                       
    Section number: 1                                                         
Number of result sets is 1                                                    
Return Status: Execution=0, Debug=0                                           

一切看起来都很好。

客户端在 while (rs1.next()) 获得 java.lang.NullPointerException

4

0 回答 0