title: How in JDBC can you call a stored procedure when only setting some parameters
body: <p>What is the best way to make a call to a stored procedure using JDBC if you only want to set some of the parameters?</p>
  
  <p>If I was just using SQL, I could set the paramerers by name in the SQL to call the sproc.  E.g. if I have a stored procedure with nine parameters and I wanted to set parameters 1,2 and 9, leaving the rest to their default values, I can run this SQL:</p>
  
  <pre><code>exec my_stored_procedure
      @parameter_1       = "ONE",
      @parameter_2       = "TWO",
      @parameter_9       = "NINE"
  </code></pre>
  
  <p>Using JDBC (Specifically jConnect 6.0), it seems that when using a CallableStatement, you have to set the parameters by their integer index, not their name.  If I try the to create a CallableStatement for the above stored procedure, with 9 parameters, and only set parameters 1,2 and 9, like this:</p>
  
  <pre><code>myStoredProcedureCall = 
    sybConn.prepareCall("{call my_stored_procedure (?, ?, ?, ?, ?, ? , ?, ?, ?)}");
  myStoredProcedureCall.setString(1, "ONE");
  myStoredProcedureCall.setString(2, "TWO");
  myStoredProcedureCall.setString(9, "NINE");
  ResultSet paramResults = myStoredProcedureCall.executeQuery();
  </code></pre>
  
  <p>Then I get this SQLException thrown:</p>
  
  <pre><code>*** SQLException caught ***
  SQLState: JZ0SA
  Message:  JZ0SA: Prepared Statement: Input parameter not set, index: 2.
  Vendor:   0
  </code></pre>
  
  <p>For some background on what I am trying to do, I need to create a process that receives information about products from a IBM MQ stream, and then creates a product in a 3rd application.  The 3rd party application uses Sybase to store it's data, and to create a product I need to call a stored procedure that has about 130 parameters.  For the type of product I need to create, only about 15 of these parameters need to be set, the rest will be left to the default values.</p>
  
  <p>Options I have considered are:</p>
  
  <ul>
  <li>Creating a custom stored procedure that sets only the values that I need, then calls the 3rd party product sproc.</li>
  <li>Setting default values for all parameters in the Java.</li>
  </ul>
  
  <p>Surely there must be an easier way to do this?</p>