Skip to content Skip to sidebar Skip to footer

Using Header Value As Table Name In Camel Sql Component

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

Solution 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}")).

Solution 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.


Post a Comment for "Using Header Value As Table Name In Camel Sql Component"