I am trying to update the Oracle table row using jdbcTemplate as follows
String sql = "update EVENTS set status = null where TEMP_ID IN (select TEMP_ID from EVENTS where STATUS = 'COMPLETE' and EXCHANGE_ID IN (?) )";
Map<String, Object> paramMap = new HashMap<String, Object>();
List<Long> longValues = new ArrayList<Long>();
longValues.add(1);
longValues.add(2);
paramMap.put("EXCHANGE_ID", longValues);
int rowsAffected = this.jdbcTemplate.update(sql,paramMap,Long.class);
where EXCHANGE_ID is a column in EVENTS table with data type NUMBER(6,0).
When I try to run the above program it is throwing an exception as follows
PreparedStatementCallback; uncategorized SQLException for SQL [update EVENTS set status = null where TEMP_ID IN (select TEMP_ID from EVENTS where STATUS = 'COMPLETE' and EXCHANGE_ID= ? )]; SQL state [99999]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type
Edit : Number of Parameters in In clause are not fixed. so number of Parameters can be 2 ,3 depending upon the user.
for simplicity I have added following lines in code
longValues.add(1);
longValues.add(2);
In reality I am receiving Parameters from the form. I have just added part of code in my question.
Due to some constraints I can only use ? at my Parameter place in my sql query not :EXCHANGE_ID
Updated: You need to use :EXCHANGE_ID in the SQL sentence:
final String sql = "update EVENTS set status = null where TEMP_ID IN (select TEMP_ID from EVENTS where STATUS = 'COMPLETE' and EXCHANGE_ID = :EXCHANGE_ID)";
final MapSqlParameterSource params = new MapSqlParameterSource();
params.put("EXCHANGE_ID", Long.valueOf(1));
int rowsAffected = this.jdbcTemplate.update(sql, params);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.