The code that causes the exception is the following:
for (int i = 0; i < 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();
}
The exact row of the exception is s.execute.
The stracktrace is:
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)
The insert query is:
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, ?, ?, ?)
Params are:
[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]]]
Googling the exception message gives nothing. I'm a newbie in DB2. Can anybody help me?
UPDATE
An example of how I set parameters in the preparedstatement:
public void setParamsPreparedStatement(PreparedStatement s, String[][] params) throws Exception {
log.debug("Params are: " + Arrays.deepToString(params));
for (int i = 0; i < params.length; i++) {
if (params[i][1].equals(ParamTypes.ORA_TYPE_INTEGER)) {
if (params[i][0] != null && !params[i][0].trim().equals("")) {
s.setInt(i + 1, Integer.parseInt(params[i][0]));
} else {
s.setNull(i + 1, Types.INTEGER);
}
}
...
}
SOLUTION
I was trying to put a long string into a field that was too short. Now the field is longer and my code succeeds.