• <bdo id='7ejin'></bdo><ul id='7ejin'></ul>
    <tfoot id='7ejin'></tfoot>

  • <legend id='7ejin'><style id='7ejin'><dir id='7ejin'><q id='7ejin'></q></dir></style></legend>

    <i id='7ejin'><tr id='7ejin'><dt id='7ejin'><q id='7ejin'><span id='7ejin'><b id='7ejin'><form id='7ejin'><ins id='7ejin'></ins><ul id='7ejin'></ul><sub id='7ejin'></sub></form><legend id='7ejin'></legend><bdo id='7ejin'><pre id='7ejin'><center id='7ejin'></center></pre></bdo></b><th id='7ejin'></th></span></q></dt></tr></i><div id='7ejin'><tfoot id='7ejin'></tfoot><dl id='7ejin'><fieldset id='7ejin'></fieldset></dl></div>

    1. <small id='7ejin'></small><noframes id='7ejin'>

        DB2 java 存储过程调用返回错误 SQLCODE=-440, SQLSTATE=42884

        时间:2023-05-27

        <tfoot id='CUueg'></tfoot>
          <tbody id='CUueg'></tbody>

          <legend id='CUueg'><style id='CUueg'><dir id='CUueg'><q id='CUueg'></q></dir></style></legend>

            <i id='CUueg'><tr id='CUueg'><dt id='CUueg'><q id='CUueg'><span id='CUueg'><b id='CUueg'><form id='CUueg'><ins id='CUueg'></ins><ul id='CUueg'></ul><sub id='CUueg'></sub></form><legend id='CUueg'></legend><bdo id='CUueg'><pre id='CUueg'><center id='CUueg'></center></pre></bdo></b><th id='CUueg'></th></span></q></dt></tr></i><div id='CUueg'><tfoot id='CUueg'></tfoot><dl id='CUueg'><fieldset id='CUueg'></fieldset></dl></div>
          • <small id='CUueg'></small><noframes id='CUueg'>

            • <bdo id='CUueg'></bdo><ul id='CUueg'></ul>

                  本文介绍了DB2 java 存储过程调用返回错误 SQLCODE=-440, SQLSTATE=42884的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在对 DB2 进行一个简单的存储过程调用.当它调用存储过程时,它总是返回这个错误:

                  I am doing a simple stored procedure call to DB2. While it calls the stored procedure, it always returns this error:

                  DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884, SQLERRMC=MEDIAN_RESULT_SET;PROCEDURE, DRIVER=3.66.46
                  

                  ========== Java 代码:

                  ========== Java code:

                  String JDBC_DRIVER = "com.ibm.db2.jcc.DB2Driver";
                  // STEP 2: Register JDBC driver
                  Class.forName(JDBC_DRIVER);
                  
                  // STEP 3: Open a connection
                  System.out.println("Connecting to database..."); 
                  conn = DriverManager.getConnection(DB_URL, USER, PASS);
                  
                  // to execute the stored procedure.
                  System.out.println("CALL median_result_set(?)");
                  String sql = "CALL median_result_set(?)";
                  CallableStatement stmt1 = conn.prepareCall(sql);
                  stmt1.registerOutParameter(1, Types.DOUBLE);
                  
                  stmt1.execute();
                  System.out.println("jdbcadapter->callproc after execute " + sql);
                  stmt1.close();
                  
                  conn.close();
                  

                  ===============db2 clp 命令行有效:

                  ============== The db2 clp command line worked:

                  c:SP>db2 call median_result_set(?)
                   Value of output parameters 
                   --------------------------
                   Parameter Name  : MEDIANSALARY 
                   Parameter Value : +7.68582000000000E+004
                  
                  Result set 1
                  --------------
                  NAME      JOB   SALARY
                  --------- ----- ---------
                  Marenghi  Mgr    77506.75
                  O'Brien   Sales  78006.00
                  

                  ================存储过程定义:

                  ================ The stored procedure definition:

                  CREATE PROCEDURE median_result_set
                  -- Declare medianSalary as OUT so it can be used to return values
                  (OUT medianSalary DOUBLE)
                  RESULT SETS 2
                  LANGUAGE SQL
                  BEGIN
                  
                     DECLARE v_numRecords INT DEFAULT 1;
                     DECLARE v_counter INT DEFAULT 0;
                  
                     DECLARE c1 CURSOR FOR
                        SELECT salary FROM staff
                         ORDER BY CAST(salary AS DOUBLE);
                  
                    -- use WITH RETURN in DECLARE CURSOR to return a result set
                    DECLARE c2 CURSOR WITH RETURN FOR
                     SELECT name, job, salary
                     FROM staff 
                     WHERE CAST(salary AS DOUBLE) > medianSalary
                     ORDER BY salary;
                  
                    -- use WITH RETURN in DECLARE CURSOR to return another result set
                   DECLARE c3 CURSOR WITH RETURN FOR
                      SELECT name, job, salary
                      FROM staff
                      WHERE CAST(salary AS DOUBLE) < medianSalary
                      ORDER BY SALARY DESC;
                  
                   DECLARE CONTINUE HANDLER FOR NOT FOUND
                     SET medianSalary = 6666; 
                  
                   -- initialize OUT parameter
                   SET medianSalary = 0;
                  
                   SELECT COUNT(*) INTO v_numRecords FROM STAFF;
                  
                   OPEN c1;
                  
                     WHILE v_counter < (v_numRecords / 2 + 1) DO
                       FETCH c1 INTO medianSalary;
                       SET v_counter = v_counter + 1;
                    END WHILE;
                    CLOSE c1;
                  
                    -- return 1st result set, do not CLOSE cursor
                    OPEN c2;
                  
                    -- return 2nd result set, do not CLOSE cursor
                    OPEN c3;
                  END @
                  

                  推荐答案

                  基本上SQLCODE=-440, SQLSTATE=42884"表示找不到存储过程.

                  Basically "SQLCODE=-440, SQLSTATE=42884" means that stored procedure can not be found.

                  我看到一个很常见的原因是参数不匹配.

                  I saw a very common cause is the argument doesn't match.

                  就我而言,我注意到在 java 代码中,我必须将架构名称放在存储过程名称的前面,例如,而不是 median_result_set(?),我应该使用 SCHEMANAME.median_result_set(?)

                  For my case, I noticed that in java code, I have to put the schema name in front of the stored procedure name, e.g, instead of median_result_set(?), I should do SCHEMANAME.median_result_set(?)

                  可以使用一些数据库管理工具找到此 SP 的 SCHEMANAME.

                  The SCHEMANAME for this SP can be found with some DB admin tools.

                  我不需要从命令行指定架构名称的原因:似乎当我在创建该 SP 时使用同一用户从 CLP 命令行调用 SP 时,不需要架构名称(因为它们在内部匹配).当然,在命令行中指定模式总是正确的.我观察到 DB2 在内部使用用户名作为模式名.例如,如果ADMINISTRATOR"创建了一个 SP,那么字符串ADMINISTRATOR"就是它的架构名称,只要我在 Windows 上看到.

                  The reason why I don't need to specify the schema name from the command line: it seems that when I call SP from CLP command line with the same user when I created that SP, there is no need to the schema name (because internally they match up). Of course, it is always right if you specify the schema at the command line. I observed DB2 internally uses user name as schema name. E.g, if "ADMINISTRATOR" created a SP, the string "ADMINISTRATOR" is its schema name, as long as I see on Windows.

                  这篇关于DB2 java 存储过程调用返回错误 SQLCODE=-440, SQLSTATE=42884的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:通过 JDBC 连接到 DB2 时的用户名和密码 下一篇:JPA 自动 BigDecimal 转换

                  相关文章

                    <bdo id='0KRXE'></bdo><ul id='0KRXE'></ul>

                  <small id='0KRXE'></small><noframes id='0KRXE'>

                1. <legend id='0KRXE'><style id='0KRXE'><dir id='0KRXE'><q id='0KRXE'></q></dir></style></legend>
                2. <tfoot id='0KRXE'></tfoot>

                3. <i id='0KRXE'><tr id='0KRXE'><dt id='0KRXE'><q id='0KRXE'><span id='0KRXE'><b id='0KRXE'><form id='0KRXE'><ins id='0KRXE'></ins><ul id='0KRXE'></ul><sub id='0KRXE'></sub></form><legend id='0KRXE'></legend><bdo id='0KRXE'><pre id='0KRXE'><center id='0KRXE'></center></pre></bdo></b><th id='0KRXE'></th></span></q></dt></tr></i><div id='0KRXE'><tfoot id='0KRXE'></tfoot><dl id='0KRXE'><fieldset id='0KRXE'></fieldset></dl></div>