title: Parameter @x was not defined for stored procedure... with MS_SQL JDBC
body: <p>I am trying to execute a stored procedure using SQL Server JDBC in a method:</p>
  
  <pre><code>//Connection connection, String sp_name, Map&lt;String, Object&gt;params input to the method
  DatabaseMetaData dbMetaData = connection.getMetaData();
  HashMap&lt;String, Integer&gt; paramInfo = new HashMap&lt;String, Integer&gt;();
  if (dbMetaData != null)
  {
          ResultSet rs = dbMetaData.getProcedureColumns (null, null, sp_name.toUpperCase(), "%");
          while (rs.next())
              paramInfo.put(rs.getString(4), rs.getInt(6));
          rs.close();
  }
  String call = "{ call " + sp_name + " ( ";
  for (int i = 0; i &lt; paramInfo.size(); i ++)
      call += "?,";
  if (paramInfo.size() &gt; 0)
      call = call.substring(0, call.length() - 1);
  call += " ) }";
  CallableStatement st = connection.prepareCall (call);
  for (String paramName: paramInfo.keySet()){
      int paramType = paramInfo.get(paramName);
      System.out.println("paramName="+paramName);
      System.out.println("paramTYpe="+paramType);
      Object paramVal = params.get(paramName);
      st.setInt(paramName, Integer.parseInt(((String)paramVal))); //All stored proc parameters are of type int
  }
  </code></pre>
  
  <p>Let say the stored procedure name is <code>ABC</code> and parameter is <code>@a</code>. 
  Now <code>DatabaseMetaData</code> returns column name <code>@a</code> but setting <code>st.setInt("@a",0)</code> returns following error:</p>
  
  <blockquote>
    <p>com.microsoft.sqlserver.jdbc.SQLServerException: Parameter @a was not defined for stored procedure ABC.</p>
  </blockquote>
  
  <p>Instead, I tried this: <code>st.setInt("a",0)</code> and it executed perfectly. </p>
  
  <p>Now the problem is I have to set the parameters dynamically as I have too many stored procedures and too many parameters but jdbc is giving error.</p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>As pointed out in one answer that my question is a duplicate of: <a href="https://stackoverflow.com/questions/2309970/named-parameters-in-jdbc">Named parameters in JDBC</a>, I would like to explain that the issue here is not named parameters or positional ones, rather it is about JDBC not handling the SQL server parameters itself properly or my making some error while invoking it.</p>