Using header value as table name in Camel sql component

好久不见. 提交于 2019-12-25 03:58:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!