...
Maven users will need to add the following dependency to their pom.xml
for this component:
Code Block |
---|
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
|
Warning |
---|
This component can only be used to define producer endpoints, which means that you cannot use the JDBC component in a from() statement. |
Info |
---|
This component can not be used as a Transactional Client. If you need transaction support in your route, you should use the SQL component instead. |
URI format
Code Block |
---|
jdbc:dataSourceName[?options]
|
...
In the given route below, we want to get all the projects from the projects table. Notice the SQL query has 2 named parameters, :?lic and :?min.
Camel will then lookup these parameters from the message headers. Notice in the example above we set two headers with constant value
for the named parameters:
Code Block |
---|
from("direct:projects")
.setHeader("lic", constant("ASF"))
.setHeader("min", constant(123))
.setBody("select * from projects where license = :?lic and id > :?min order by id")
.to("jdbc:myDataSource?useHeadersAsParameters=true")
|
...
If we want to poll a database using the JDBC component, we need to combine it with a polling scheduler such as the Timer or Quartz etc. In the following example, we retrieve data from the database every 60 seconds:
Code Block |
---|
|
from("timer://foo?period=60000").setBody(constant("select * from customer")).to("jdbc:testdb").to("activemq:queue:customers");
|
Include Page |
---|
| Endpoint See Also |
---|
| Endpoint See Also |
---|
|