Integration / Apache Camel Interview Questions
How does Camel integrate with databases using the SQL and JDBC components?
Camel provides two primary database components: camel-sql for declarative SQL route integration and camel-jdbc for low-level JDBC execution. Both require a configured DataSource in the registry (injected via Spring or registered manually in CamelContext).
// SQL: SELECT, body becomes List of row maps
from("timer:poll?period=60000")
.to("sql:SELECT * FROM orders WHERE status=:#status")
.split(body()).to("direct:processOrder");
// SQL: INSERT with named parameters from headers
from("direct:storeOrder")
.to("sql:INSERT INTO orders(id,status) VALUES(:#orderId,:#status)");
// JDBC: execute query in message body
from("direct:runQuery")
.setBody(constant("SELECT product_id, price FROM products WHERE active=1"))
.to("jdbc:myDataSource");The SQL component uses :#paramName named parameters mapped from headers (for simple names) or Exchange properties. Results are a List<Map<String, Object>>. The JDBC component takes the SQL from the message body. The header CamelJdbcRowCount gives the number of rows returned. For transactional execution, combine with a TransactionErrorHandler and a PlatformTransactionManager.
More Related questions...