title: Stored procedure and prepared statement error
body: <p>I am calling a stored procedure from my Java application and getting the following error while setting the input parameter. </p>
  
  <p>1: Java method for calling the procedure: </p>
  
  <pre><code>public int callProc(String userid, String program_id, String procName)
          throws SQLException {
  
      int returnCode = -1;
  
      try {
  
          CallableStatement stmt;
  
          String sql = "CALL " + procName + "(?,?,?,?,?)";
          stmt = connection.prepareCall(sql);
  
          System.out.println("Calling stored procedure [" + procName + "]");
  
          // call setXXX() method to set values for input parameters
          // and input-output parameters
          System.out.println("jdbcadapter-&gt;callproc setting 1 parameter "+stmt);
          stmt.setObject(1, userid, java.sql.Types.CHAR);
          System.out.println("jdbcadapter-&gt;callproc setting 2 parameter "+sql);
          stmt.setObject(2, program_id, java.sql.Types.CHAR);
          System.out.println("jdbcadapter-&gt;callproc setting 3 parameter "+sql);
          stmt.setObject(3, session_id, java.sql.Types.CHAR);
          System.out.println("jdbcadapter-&gt;callproc setting 4 parameter "+sql);
          stmt.setObject(4, " ", java.sql.Types.CHAR);
          System.out.println("jdbcadapter-&gt;callproc setting 5 parameter "+sql);
          stmt.setObject(5, " ", java.sql.Types.CHAR);
          System.out.println("jdbcadapter-&gt;callproc setting 6 parameter "+sql);
          // call registerOutParameter() method to define the data types for output parameters
          stmt.registerOutParameter(4, java.sql.Types.CHAR); // rc
          System.out.println("jdbcadapter-&gt;callproc setting 7 parameter "+sql);
          stmt.registerOutParameter(5, java.sql.Types.CHAR); // result message
          System.out.println("jdbcadapter-&gt;callproc setting 8 parameter "+sql);
  
          stmt.execute();
          System.out.println("jdbcadapter-&gt;callproc after execute "+sql);
  
          String rc = stmt.getString(4);
          System.out.println("jdbcadapter-&gt;callproc after execute "+rc);
          String message = stmt.getString(5);
          System.out.println("jdbcadapter-&gt;callproc after execute "+message);
          Integer return_code = new Integer(rc.trim());
          System.out.println("jdbcadapter-&gt;callproc after execute "+return_code);
          returnCode = return_code.intValue();
          System.out.println("jdbcadapter-&gt;callproc after execute "+returnCode);
          return_message = message.trim();
          System.out.println("jdbcadapter-&gt;callproc after execute "+return_message);
          System.out.println("Returned code from stored procedure is ["+ rc.trim() + "]");
          stmt.close();
  
      } catch (Exception e) {
          throw ((SQLException) e);
      }
  
      return returnCode;
  
  } // end callProc()
  </code></pre>
  
  <p>The problem is occuring while setting the USER ID in the stmt at </p>
  
  <pre><code>stmt.setObject(1, userid, java.sql.Types.CHAR);
  </code></pre>
  
  <p>Definition of Stored procedure on database side</p>
  
  <pre><code>CREATE PROCEDURE "CDR     "."SPUBASE"
                  (
                  IN      USERID   CHARACTER(12),
                  IN      PROGRAM_ID   CHARACTER(20),
                  IN      SESSION_ID   CHARACTER(27),
                  OUT     SQLCODE   CHARACTER(254),
                  OUT     SQLMESSAGE   CHARACTER(254)
                  )
                  DYNAMIC RESULT SETS 0
                  SPECIFIC SQL040816123726847
                  EXTERNAL NAME '/cdrtst/sqllib/function/SPUBASE!SPUBASE'
                  LANGUAGE C
                  PARAMETER STYLE DB2DARI
                  NOT DETERMINISTIC
                  FENCED NOT THREADSAFE
                  MODIFIES SQL DATA
                  NO DBINFO;
  </code></pre>
  
  <p>and the error is </p>
  
  <pre><code>SQLException: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884, SQLERRMC=SPUBASE;PROCEDURE, DRIVER=4.1.85 
  </code></pre>
  
  <p>Could anyone suggest what can cause this.</p>