title: Getting parameter values from Callablestatement
body: <p>I have lots of stored procedure calls in my app and we are using callable statements. At times we need to debug the parameters being passed to the stored proc, there is no easy way but to write code print all the values coming from the entity object.</p>
  
  <p>So I was trying to make a generic function which will take in the callable statement signature, and the callable statement object after execution and for the SQL which was executed and print in logs for debugging. I wrote the following code, but its throwing sql exception "Parameter type not valid" on switch case 1's cs.getString.</p>
  
  <p>Here the parameter type is 1 as retrieved from cs metadata, and as per the <a href="http://docs.oracle.com/javase/6/docs/api/constant-values.html#java.sql.Types.CHAR" rel="nofollow">javadoc</a> the constant 1 is for CHAR, which should map to string in java. Even my actual set parameter for this stored procedure is also using String, which works fine, so why getString is failing with this exception?</p>
  
  <p>I am using AS400 driver.</p>
  
  <pre><code>        StringBuffer sb = new StringBuffer("{ call ").append(storProcName)
                  .append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }");
          cs = connection.prepareCall(sb.toString());
          // Get and set all parameters
          cs.executeUpdate();
          ParameterMetaData paramd = cs.getParameterMetaData();
          int index, type;
          for (int i = 1; i &lt; paramd.getParameterCount(); i++) {
              type = paramd.getParameterType(i);
              index = sb.indexOf("?");
              if (paramd.getParameterMode(i) == ParameterMetaData.parameterModeIn) {
                  switch (type) {
                  case 1:
                      sb = sb.replace(index, index + 1, "'" + cs.getString(i)
                              + "'");
                      break;
                  }
              }
          }
  </code></pre>