title: Java - Calling a stored procedure with generic arguments
body: <p>I would like to call a stored procedure (Oracle). As I my procedure calls are dynamical, I need to manage the procedures parameters dynamically.
  The problem is that I would like to avoid using the <code>instanceof</code> keyword since it does not work well with primary types.
  Is there a cleaner way to call a such procedure?</p>
  
  <pre><code>    public void executeProcedure(StoredProcedure proc) {        
          LinkedList&lt;ProcedureParameter&lt;?&gt;&gt; parameters = proc.getParameters();
  
          CallableStatement statement = connection.prepareCall("{ call MY_PACKAGE.MY_PROCEDURE( ?, ?, ? ) }");
  
          for (int i = 0; i &lt; parameters.size(); i++) {
              Object paramValue = parameters.get(i).getValue();
  
              // Beginning of smelly code
  
              if (paramValue instanceof String) {
                  statement.setString(i + 1, (String) paramValue);
              }
              else if (paramValue instanceof ...) {
                  ...
              }
              else {
                  ...
              }
  
              // End of smelly code
          }
  
          statement.execute();            
      }
  </code></pre>
  
  <p> </p>
  
  <pre><code>    public class ProcedureParameter&lt;E&gt; {
          private String name;
          private E value;
  
          public ProcedureParameter(String name) {
              this.name = name;
          }
  
          public ProcedureParameter(String name, E value) {
              this.name = name;
              this.value = value;
          }
  
          // Getters and setters
      }
  </code></pre>
  
  <p>Thank you for any idea.</p>