Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: CAMEL-658

...

The jdbc: component allows you to work with databases using JDBC queries and operations via SQL text as the message payload.
This component uses standard Java JDBC to work with the database, unlike the SQL component that uses spring-jdbc.

URI format

Code Block
jdbc:dataSourceName?options

This component only supports producer, meaning that you can not use routes with this component in the from type.

Options

Name

Default Value

Description

readSize

20000 2000

The default maximum number of rows that can be read by a polling query

...

The result is returned in the out body as a ArrayList<HashMap<String, Object>> list object with the result. The ArrayList List contains the list of rows and the Map contains each row with the string key as the column name.

Note: This component fetches ResultSetMetaData to be able to return the column name as the key in the Map.

If the query is an update query the update count is returned in the header jdbc.updateCount

Samples

In the sample below we fetches the rows from the customer table.

...

Wiki Markup
{snippet:id=invoke|lang=java|url=activemq/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcRouteTest.java}

Sample - Polling the database every minute

If we want to poll a database using this component we need to combine this with a polling scheduler such as the Timer or Quartz etc.
In this sample we retrieve data from the database every 60th seconds.

Code Block
java
java

from("timer://foo?period=60000").setBody(constant("select * from customer")).to("jdbc:testdb").to("activemq:queue:customers");
Include Page
CAMEL:Endpoint See Also
CAMEL:Endpoint See Also