MuleESB / 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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
