0

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.

praveenps
  • 77
  • 1
  • 9
  • One workaround would be to add a bean or processor and just do the JDBC calls inside a method using the passed in Exchange object to access the headers. I have done this many times I have run up against component issues and it works like a charm. – java-addict301 Oct 20 '17 at 15:45
  • Try also upgrading to a newer Camel version – Claus Ibsen Oct 20 '17 at 15:55

1 Answers1

1

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.

Umair Saleem
  • 1,055
  • 5
  • 19