title: How to pass multiple parameters to a PreparedStatement in java?
body: <p>I am using the below code to retrive the order data from db2 and it works fine when i am passing only the BranchNumber and used the getWildcards() function since sometime i am passing multiple branch numbers .</p>
  
  <pre><code>public List&lt;Order&gt; getallorders(List&lt;Branch&gt; BranchNumber) throws SQLException {
          List&lt;Order&gt; orders = new ArrayList&lt;Order&gt;();        
          try {               
              StringBuilder sb = new StringBuilder();
              sb.append("SELECT ORDER_NUMBER as ordernumber,SERVICE_TYPE as service"
                      + "FROM ORDER WHERE "
                      + "BRANCH IN(");            
              sb.append(getWildCards(BranchNumber.size())).append(")").append(" WITH UR");
              String query = sb.toString();
              PreparedStatement statement = connection.prepareStatement(query);           
              for(int i=0 ; i&lt;BranchNumber.size() ;i++)
              {
              statement.setInt(i+1,BranchNumber.get(i).getBranch()); 
              }
              ResultSet resultSet  = statement.executeQuery();
              {
              while (resultSet .next()) {
                  Order order1 = new Order();
                  order1.setOrdernumber(resultSet.getInt("ordernumber")); 
                  orders.add(order1);                
              }            
              }            
          }
          catch (SQLException e) {
              e.printStackTrace();
          }
          return orders;
  }
  
  
      private String getWildCards(int size) {
          // TODO Auto-generated method stub
          StringBuilder sb = new StringBuilder();
          for(int i =0 ; i&lt;size ; i++)
  
          {
               sb = (i == 0) ? sb.append("?") 
                       : sb.append(",").append("?");
  
          }
          return sb.toString();
      }
  </code></pre>
  
  <p>Now i need to pass the startDate and endDate inside the function to retrieve the data but the preparedstatement is not formatting the select query with the passed value .</p>
  
  <pre><code>public List&lt;Order&gt; getallorders(List&lt;Branch&gt; BranchNumber,String startDate,String endDate) throws SQLException {
          List&lt;Order&gt; orders = new ArrayList&lt;Order&gt;();        
          try {               
              StringBuilder sb = new StringBuilder();
              sb.append("SELECT ORDER_NUMBER as ordernumber,SERVICE as service"
                      + "FROM ORDER WHERE "
                      + "BRANCH IN(");            
              sb.append(getWildCards(BranchNumber.size())).append(")");
              sb.append("AND ORDERDATE BETWEEN ? and ?  WITH UR");
              String query = sb.toString();
              PreparedStatement statement = 
   connection.prepareStatement(query);            
              for(int i=0 ; i&lt;BranchNumber.size() ;i++)
              {
              statement.setInt(i+1,BranchNumber.get(i).getBranch()); 
              }
              ResultSet resultSet  = statement.executeQuery();
              {
              while (resultSet .next()) {
                  Order order1 = new Order();
                  order1.setOrdernumber(resultSet.getInt("ordernumber")); 
                  orders.add(order1);                
              }            
              }            
          }
          catch (SQLException e) {
              e.printStackTrace();
          }
          return orders;
  }
  </code></pre>
  
  <p>Can someone please explain me what i am doing wrong here and how i can get the expected preparedstatement,below is the formatted query coming in my log and error message recorded,</p>
  
  <pre><code>SELECT ORDER_NUMBER as ordernumber,SERVICE_TYPE as service FROM .ORDER WHERE 
  BRANCH_NUMBER IN(?) + AND ORDERDATE BETWEEN ? AND ? WITH UR
  
  com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, 
  SQLSTATE=42601, SQLERRMC=ORDER DATE BETWEEN ? AND;H_NUMBER IN(?) + AND;
  &lt;order_siblings_by&gt;, DRIVER=3.63.75
  at com.ibm.db2.jcc.am.fd.a(fd.java:679)
  </code></pre>