问题
I would like to use the header value for setting the name of db table in sql component. Is there an easy way to do this? .to("sql:drop table ${in.header.tablename}") throws invalid character exception
回答1:
If you want to route the message dynamically, you can use recipient-list. The route could be
from("direct:a").recipientList(simple("sql:drop table ${in.header.tablename}")).
回答2:
The point of using the sql component instead of the jdbc one is that the former allows you to use the message payload as parameters to the query.
For what you want, just use named parameters to access the headers from the query. There is an example right in the sql component docs :
from("direct:projects")
.setHeader("lic", constant("ASF"))
.setHeader("min", constant(123))
.to("sql:select * from projects where license = :#lic and id > :#min order by id")
Hope it helps.
来源:https://stackoverflow.com/questions/24768425/using-header-value-as-table-name-in-camel-sql-component