title: com.microsoft.sqlserver.jdbc.SQLServerException: The index 8 is out of range
body: <p>I am trying the following code:</p>
  
  
  
  <pre><code>public class StoredProcedureParam 
  {
      private String m_sType; 
      private String m_sValue;
      private String m_sParamName;
  
      public StoredProcedureParam(String a_sParamName, String a_sType, String a_sValue)
      {
          m_sType = a_sType;
          m_sValue = a_sValue;
          m_sParamName = a_sParamName;
      }
  }
  
  ArrayList&lt;StoredProcedureParam&gt; spmArr = new ArrayList&lt;StoredProcedureParam&gt;();
  
  spmArr.add(new StoredProcedureParam("sBridgePhone",             "NString",  "value1"));
  spmArr.add(new StoredProcedureParam("sCallerPaidTelNumber",             "NString",  "value2"));
  spmArr.add(new StoredProcedureParam("sTollFreeTelNumber",       "NString",  "default"));
  spmArr.add(new StoredProcedureParam("sParticipantAccessCode",   "NString",  "value3"));
  spmArr.add(new StoredProcedureParam("sHostPassword",            "NString",  "value4"));
  spmArr.add(new StoredProcedureParam("tNowUtc",                  "output",   "timestamp"));
  spmArr.add(new StoredProcedureParam("nStatusCode",              "output",   "Int"));
  
  if (!m_jdbcWrapper.callStoredProcedure("{call spAddConference(?,?,?,?,?,?,?)}", spmArr)) {
      System.out.println("callAddConferenceSp - Failed to execute");
      return "";
  }
  
  
  public boolean callStoredProcedure(String a_sStoredProcedure, ArrayList&lt;StoredProcedureParam&gt; a_ParamList)
  {                   
      try 
      {
          connect();          
  
          m_cStatement = m_Connection.prepareCall(a_sStoredProcedure,
                                              ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                              ResultSet.CONCUR_READ_ONLY);
  
          registerSpParams(a_ParamList);
  
          m_cStatement.execute();         
      } 
      catch (SQLException ex) 
      {
          ex.printStackTrace();
          return false;
      }
      finally 
      {
          try 
          {
              m_cStatement.close();
              System.out.println("JDBCWrapper - Statement Closed!");
              m_Connection.close();
              System.out.println("JDBCWrapper - Connection Closed!");             
          } 
          catch (SQLException e) 
          {
              e.printStackTrace();
          }
      }
  
      return true;
  }
  
  
  private void registerSpParams(ArrayList&lt;StoredProcedureParam&gt; a_ParamList) throws SQLException {
  
          if (a_ParamList.size() &gt; 0)
          {
              for (int i = 1; i &lt;= a_ParamList.size(); i++)
              {
                  StoredProcedureParam spp = a_ParamList.get(i - 1);
                  switch (TypesEnum.valueOf(spp.getType()))
                  {
                      case Integer:
                          m_cStatement.setInt(spp.getParamName(), Integer.parseInt(spp.getValue()));
                          break;
                      case String: 
                          m_cStatement.setString(spp.getParamName(), spp.getValue());
                          break;
                      case NString:
                          m_cStatement.setNString(spp.getParamName(), spp.getValue());
                          break;
                      case Timestamp:
                          m_cStatement.setTimestamp(spp.getParamName(), Timestamp.valueOf(spp.getValue()));
                          break;
                      case output:
                          switch (TypesEnum.valueOf(spp.getValue()))
                          {
                              case Integer:
                                  m_cStatement.registerOutParameter(spp.getParamName(), java.sql.Types.INTEGER);
                                  break;
                              case Timestamp:
                                  m_cStatement.registerOutParameter(spp.getParamName(), java.sql.Types.TIMESTAMP);
                                  break;
                              default:
                                  break;
                          }
                          break;
                      case bit:
                          m_cStatement.setByte(spp.getParamName(), Byte.parseByte(spp.getValue()));
                          break;
                      case Bigint:
                          m_cStatement.setBigDecimal(spp.getParamName(), BigDecimal.valueOf(Long.parseLong(spp.getValue())));
                          break;
                  }
              }
          }
      }
  </code></pre>
  
  <p>For some reason I am getting the exception in subject:</p>
  
  <pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: The index 8 is out of range.
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
        at com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.registerOutParameter(SQLServerCallableStatement.java:75)
        at com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.registerOutParameter(SQLServerCallableStatement.java:1735)
        at com.att.ecm.jdbcwrapper.JDBCWrapper.registerSpParams(JDBCWrapper.java:216)
        at com.att.ecm.jdbcwrapper.JDBCWrapper.callStoredProcedure(JDBCWrapper.java:138)
        at com.client.main.ConferenceStoredProcedures.callAddConferenceSp(ConferenceStoredProcedures.java:74)
        at com.main.Main.startFlow(Main.java:51)
        at com.main.Main.executeFlow(Main.java:34)
        at com.main.Main.main(Main.java:26)
  </code></pre>
  
  <p>And cannot understand why? As far as I understand I set 7 question marks and set 7 parameters.
  So, why does it throws an exception on the 8th index??</p>
  
  <p>Can you advise please?</p>
  
  <p>Best Regards, Tal</p>