I am using camel 2.17.0 and have to execute an update query using SQL IN clause. Query is
update MY_TABLE set STATUS = :#status where ID in (:#in:ids) AND TYPE = :#type
I have set all the parameters to camel header, the parameter ids is a List<Long> and has four elements in the list during my execution. But I am getting a sql exception
PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Number of parameters mismatch.
Expected: 6, was: 4; nested exception is java.sql.SQLException: Number of parameters mismatch. Expected: 6, was: 4
I am not sure what went wrong. When I hard coded all the values except the parameter the list ids, I am able to update table without any error. Modified query is like
update MY_TABLE set STATUS = 'SUCCESS' where ID in (:#in:corrIds) AND TYPE = 'type'
Is there any mandate that when we use IN clause we cannot give any other parameters in the query? Please advise.
For in clause you need to update on 2.18. However, by using 2.17 just make the comma separated string and put it in the exchange header. It will be automatically mapped.
Just beware of any SQL injection by using this technique.