使用 apache camel sql 组件时数据库未更新

Database not update when using apache camel sql component

我正在尝试使用 apache camel(sql 组件)来更新数据库。问题是数据库没有得到更新。当我对查询进行硬编码时,sql:update 工作正常,但是当我尝试使用 ${body[0][id]} 时,它不会更新必填字段。关于可能出错的任何反馈?

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();

请注意,status 和 id 是整数字段,但如果我从 .to() 中删除 ',则会抛出一些错误。

根据文档,您必须使用 :# 作为占位符语法

所以试试

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

下面的代码也有效。

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();