Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 19. JoSQL


The JoSQL (SQL for Java objects) language enables you to evaluate predicates and expressions in Apache Camel. JoSQL employs a SQL-like query syntax to perform selection and ordering operations on data from in-memory Java objects—however, JoSQL is not a database. In the JoSQL syntax, each Java object instance is treated like a table row and each object method is treated like a column name. Using this syntax, it is possible to construct powerful statements for extracting and compiling data from collections of Java objects. For details, see

Adding the JoSQL module

To use JoSQL in your routes you need to add a dependency on camel-josql to your project as shown in Example 19.1, “Adding the camel-josql dependency”.

Example 19.1. Adding the camel-josql dependency

<!-- Maven POM File -->

Static import

To use the sql() static method in your application code, include the following import statement in your Java source files:
import static org.apache.camel.builder.sql.SqlBuilder.sql;


Table 19.1, “SQL variables” lists the variables that are accessible when using JoSQL.

Table 19.1. SQL variables

exchangeorg.apache.camel.ExchangeThe current Exchange
inorg.apache.camel.MessageThe IN message
outorg.apache.camel.MessageThe OUT message
propertyObjectthe Exchange property whose key is property
headerObjectthe IN message header whose key is header
variableObjectthe variable whose key is variable


Example 19.2, “Route using JoSQL” shows a route that uses JoSQL.

Example 19.2. Route using JoSQL

    <from uri="direct:start"/>
      <language language="sql">select * from MyType</language>
    <to uri="seda:regularQueue"/>