0
votes

i'm using spring jdbcTemplate.batchupdate to insert a set of records.

String SQL_QUERY = "UPDATE RECORD_TABLE SET VALUE=?,LAST_UPDATE=?, LAST_USERNAME=? WHERE RECORD_NBR=?"
List<Object[]> updateParams = new Object[]{
 myDomainVO.getBigDoubleValue(),
 myDomainVO.getLastupdateDate(),
 myDomainVO.getLastUserName(),
 myDomainVO.getRecordNbr()
};
getJdbcTemplate().batchupdate(sql,updateParams);

now my Domain object has got a double value with 22 digit, but as i execute this code, DB gets updated with 2147483647 , the Integer.MAX_VALUE.

I also tried to pass the int[] argType as third param in batchUpdate as

int[] updateParamType = new int[]{
Types.DOUBLE,Types.DATE,Types.VARCHAR,Types.NUMERIC
}

Can anyone please explain why its behaving such ?

FYI I'm using oracle 11g.

1

1 Answers

1
votes

I got two approaches working.

  1. create sqlParameter instead of plain Objects

modify the update params to be a list of SQLParameterValues.

updateParamList.add(new SqlParameterValue[] {
 new SqlParameterValue(Types.DECIMAL, myDomainVO.getBigDoubleValue()), 
 new SqlParameterValue(Types.VARCHAR, myDomainVO.getLastUserName()), 
 new SqlParameterValue(Types.DATE, myDomainVO.getLastupdateDate()),
 new SqlParameterValue(Types.BIGINT, myDomainVO.getRecordNbr())
});
  1. or use BatchPreparedStatementSetter.

pass the list object directly along with PPSS setValues().

jdbcTemplate.batchUpdate(updateStmt, myDomainVOList, 
                         new ParameterizedPreparedStatementSetter<Demand>() {

                         @Override
                         public void setValues(PreparedStatement ps, Demand argument) 
                                               throws SQLException {
                             ps.setDouble(1, argument.getDemand());
                         }
                         } 
);