Apache Camel example to insert a row into a table

I want to insert exchange.body into the database table for one of the conditions of my route.

  • Is there any camel-jdbc component example / tutorial for inserting a message body?
  • Is it possible to import the SQL query itself and pass exchange.body to it?

I looked at http://camel.apache.org/jdbc.html but could not understand.

Here the Spring example is confusing for me. I did not understand why it configures the body as an SQL query and again imports some query from the class path. (There is no sample insert request here.)

+5
source share
2 answers

, , , , , Camel, INSERT.

, . - - ​​

// In a Java bean/processor before the JDBC endpoint.
// Update: make sure to sanitize the payload from SQL injections if it contains user inputs or external data not generated by trusted sources.
exchange.getIn().setBody("INSERT INTO MYTABLE VALUES('" + exchange.getIn().getBody(String.class) + "', 'fixedValue', 1.0, 42)");

, , , , , , SQL-.

,

 <jdbc:embedded-database id="testdb" type="DERBY">
        <jdbc:script location="classpath:sql/init.sql"/>
 </jdbc:embedded-database>

, JDBC, (Apache Derby) ( sql/init.sql). jdbc, JDBC.

, SQL .

+5

( ) - SQL.

SQL - JDBC.

SQL:

from("direct:start").to("sql:insert into table foo (c1, c1) values ('#','#')");

com.google.common.collect.Lists;
producerTemplate.sendBody("direct:start", Lists.newArrayList("value1","value2"));

Using the JDBC Component:

from("direct:start").to("jdbc:dataSource");

producerTemplate.sendBody("direct:start", "insert into table foo (c1, c1) values ('value1','value2')");
+6
source

All Articles