Database not update when using apache camel sql component

1.9k views Asked by At

I'm trying to use apache camel (sql component) to update the DB. Problem is that the DB just doesn't get updated. The sql:update is working fine when i hard code the query, but when i try to use ${body[0][id]} it doesn't update required field. Any feedback on what might be going wrong?

from("direct:updateSql")
.to("sql:select * from mytable limit 1")
.log("update mytable set status = '100' where id = '${body[0][id]}'")
.to("sql:update mytable set status = '100' where id = '${body[0][id]}'")
.end();

Note that status and id are integer fields but if i remove the ' from the .to() then i throws some errors.

2

There are 2 answers

0
Claus Ibsen On BEST ANSWER

According to the docs you must use :# as the placeholder syntax

So try with

.to("sql:update mytable set status = 100 where id = :#${body[0][id]}")
0
noi.m On

Below code worked too.

from("direct:updateSql")
.to("sql:select * from mytable limit 1")
.setHeader("id", simple("${body[0][id]}"))
.to("sql:update mytable set status_id = 100 where id = :#id")
.end();