title: java.sql.SQLException: Parameter number X is not an OUT parameter
body: <p>I'm struggling with getting the result OUT variable from a MySQL stored procedure. I get the following error:</p>
  
  <pre><code>java.sql.SQLException: Parameter number 3 is not an OUT parameter
  </code></pre>
  
  <p>The stored procedure looks like this:</p>
  
  <pre><code>CREATE DEFINER=`cv_admin`@`localhost` PROCEDURE `CheckGameEligibility`(
     IN gID INT(10),
     IN uID INT(10),
  
     OUT result TINYINT(1)
  )
  BEGIN
      # Do lots of stuff, then eventually:
      SET result = 1;
  END 
  </code></pre>
  
  <p>My java function takes an array of strings* and creates the CallableStatement object dynamically:</p>
  
  <pre><code>public static int callAndReturnResult( String sql , String[] values )
  {
      int out = 0 ;
      try
      {
          // construct the SQL. Creates: CheckGameEligibility(?, ?, ?)
          sql += "(" ;
  
          for( int i = 0 ; i &lt; values.length ; i++ )
          {
              sql += "?, " ;
          }
          sql += "?)" ;
  
          System.out.println( "callAndReturnResult("+sql+"): constructed SQL: " + sql );
  
          // Then the statement
          CallableStatement cstmt = DB.prepareCall( sql );
          for( int i = 0 ; i &lt; values.length ; i++ )
          {
              System.out.println( "   " + (i+1) + ": " + values[ i ] ) ;
              cstmt.setString(i+1, values[ i ] );
          }
  
          System.out.println( "   " + (values.length+1) + ": ? (OUT)" ) ;
          cstmt.registerOutParameter( values.length + 1 , Types.TINYINT );
          cstmt.execute();
  
          out = cstmt.getInt( values.length );
          cstmt.close();
      }
      catch( Exception e )
      {
          System.out.println( "*** db trouble: callAndReturnResult(" + sql + " failed: " + e );
          e.printStackTrace() ;
      }
      return out ;
  }
  </code></pre>
  
  <p>*) I suppose I should be using an int array instead of a string array, but it doesn't seem to be what the error message was about.</p>
  
  <p>Anyway, here's the output it generates:</p>
  
  <pre><code>callAndReturnResult(CheckGameEligibility(?, ?, ?)): constructed SQL: CheckGameEligibility(?, ?, ?)
  1: 57
  2: 29
  3: ? (OUT)
  *** db trouble: callAndReturnResult(CheckGameEligibility(?, ?, ?) failed: java.sql.SQLException: Parameter number 3 is not an OUT parameter
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
      at com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java:692)
      at com.mysql.jdbc.CallableStatement.registerOutParameter(CallableStatement.java:1847)
      at org.apache.commons.dbcp.DelegatingCallableStatement.registerOutParameter(DelegatingCallabl&gt;eStatement.java:92)
      at Tools.callAndReturnResult(Tools.java:156)
  </code></pre>
  
  <p>Any ideas what might be the problem? :)</p>
  
  <p>Thanks in advance!</p>