title: Update exception using JDBC on DB2
body: <p>The code that causes the exception is the following:</p>
  
  <pre><code>    for (int i = 0; i &lt; updateParams.size(); i++) {
          s = con.prepareStatement(sSQL);
          params = (String[][]) updateParams.get(i);
          setParamsPreparedStatement(s, params);
          log.debug("executeUpdates: " + sSQL + "[params:" + Arrays.deepToString(params) + "]");
          Date d = new Date();
          s.execute();
          log.info("STATEMENT EXECUTE TIME IN SECOND=" + (new Double(new Date().getTime() - d.getTime()) / 1000));
          rowcount += s.getUpdateCount();
          s.close();
      }
  </code></pre>
  
  <p>The exact row of the exception is s.execute.</p>
  
  <p>The stracktrace is:</p>
  
  <pre><code>com.ibm.db2.jcc.c.SqlException: The value of a host variable in the EXECUTE or OPEN statement is out of range for its corresponding use.
      at com.ibm.db2.jcc.c.fg.d(fg.java:1340)
      at com.ibm.db2.jcc.b.gb.k(gb.java:351)
      at com.ibm.db2.jcc.b.gb.a(gb.java:60)
      at com.ibm.db2.jcc.b.w.a(w.java:52)
      at com.ibm.db2.jcc.b.wb.c(wb.java:213)
      at com.ibm.db2.jcc.c.gg.ab(gg.java:1779)
      at com.ibm.db2.jcc.c.gg.d(gg.java:2324)
      at com.ibm.db2.jcc.c.gg.d(gg.java:2420)
      at com.ibm.db2.jcc.c.gg.X(gg.java:1332)
      at com.ibm.db2.jcc.c.gg.execute(gg.java:1316)
  </code></pre>
  
  <p>The insert query is:</p>
  
  <pre><code>insert into CMP_RULES_ACTIONS (RULE_ID, ACTION_ID, CAMPAIGN_ID, creation_date, LAST_UPDATE_DATE, expiry_date, activation_date, enabled, priority, GROUP_ID, owner) values (?, ?, ?, sysdate, sysdate, to_date(?,'YYYY/MM/DD HH24:MI'), to_date(?,'YYYY/MM/DD HH24:MI'), 1, ?, ?, ?)
  </code></pre>
  
  <p>Params are:</p>
  
  <pre><code>[params:[[freebuy_wv_scomm_bonus_perc_863, 12], [sendgenericbonuslist, 12], [863, 4], [2101/01/31 00:00, 12], [2013/03/21 16:14, 12], [0, 4], [null, 12], [null, 12]]]
  </code></pre>
  
  <p>Googling the exception message gives nothing. I'm a newbie in DB2. Can anybody help me?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>An example of how I set parameters in the preparedstatement:</p>
  
  <pre><code>public void setParamsPreparedStatement(PreparedStatement s, String[][] params) throws Exception {
      log.debug("Params are: " + Arrays.deepToString(params));
      for (int i = 0; i &lt; params.length; i++) {
          if (params[i][1].equals(ParamTypes.ORA_TYPE_INTEGER)) {
              if (params[i][0] != null &amp;&amp; !params[i][0].trim().equals("")) {
                  s.setInt(i + 1, Integer.parseInt(params[i][0]));
              } else {
                  s.setNull(i + 1, Types.INTEGER);
              }
          }
  
   ...
  }
  </code></pre>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>I was trying to put a long string into a field that was too short. Now the field is longer and my code succeeds.</p>