Chapter 306. SQL Stored Procedure Component

Available as of Camel version 2.17

The sql-stored: component allows you to work with databases using JDBC Stored Procedure queries. This component is an extension to the SQL Component but specialized for calling stored procedures.

This component uses spring-jdbc behind the scenes for the actual SQL handling.

Maven users will need to add the following dependency to their pom.xml for this component:

    <!-- use the same version as your Camel core version -->

306.1. URI format

The SQL component uses the following endpoint URI notation:


Where template is the stored procedure template, where you declare the name of the stored procedure and the IN, INOUT, and OUT arguments. 

You can also refer to the template in a external file on the file system or classpath such as:


Where sql/myprocedure.sql is a plain text file in the classpath with the template, as show:

  INTEGER ${headers.num1},
  INTEGER ${headers.num2},
  INOUT INTEGER ${headers.num3} out1,

You can append query options to the URI in the following format, ?option=value&option=value&…​

306.2. Options

The SQL Stored Procedure component supports 2 options which are listed below.


dataSource (producer)

Sets the DataSource to use to communicate with the database.



resolveProperty Placeholders (advanced)

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.



The SQL Stored Procedure endpoint is configured using URI syntax:


with the following path and query parameters:

306.2.1. Path Parameters (1 parameters):



Required Sets the StoredProcedure template to perform



306.2.2. Query Parameters (7 parameters):


batch (producer)

Enables or disables batch mode



dataSource (producer)

Sets the DataSource to use to communicate with the database.



function (producer)

Whether this call is for a function.



noop (producer)

If set, will ignore the results of the template and use the existing IN message as the OUT message for the continuation of processing



outputHeader (producer)

Store the template result in a header instead of the message body. By default, outputHeader == null and the template result is stored in the message body, any existing content in the message body is discarded. If outputHeader is set, the value is used as the name of the header to store the template result and the original message body is preserved.



useMessageBodyForTemplate (producer)

Whether to use the message body as the template and then headers for parameters. If this option is enabled then the template in the uri is not used.



synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).



306.3. Declaring the stored procedure template

The template is declared using a syntax that would be similar to a Java method signature. The name of the stored procedure, and then the arguments enclosed in parenthesis. An example explains this well:

<to uri="sql-stored:STOREDSAMPLE(INTEGER ${headers.num1},INTEGER ${headers.num2},INOUT INTEGER ${headers.num3} result1,OUT INTEGER result2)"/>

The arguments are declared by a type and then a mapping to the Camel message using simple expression. So, in this example the first two parameters are IN values of INTEGER type, mapped to the message headers. The third parameter is INOUT, meaning it accepts an INTEGER and then returns a different INTEGER result. The last parameter is the OUT value, also an INTEGER type.

In SQL term the stored procedure could be declared as:


306.3.1. IN Parameters

IN parameters take four parts separated by a space: parameter name, SQL type (with scale), type name and value source.

Parameter name is optional and will be auto generated if not provided. It must be given between quotes(').

SQL type is required and can be an integer (positive or negative) or reference to integer field in some class. If SQL type contains a dot then component tries resolve that class and read the given field. For example SQL type com.Foo.INTEGER is read from the field INTEGER of class com.Foo. If the type doesn’t contain comma then class to resolve the integer value will be java.sql.Types. Type can be postfixed by scale for example DECIMAL(10) would mean java.sql.Types.DECIMAL with scale 10.

Type name is optional and must be given between quotes(').

Value source is required. Value source populates the parameter value from the Exchange. It can be either a Simple expression or header location i.e. :#<header name>. For example Simple expression ${header.val} would mean that parameter value will be read from the header "val". Header location expression :#val would have identical effect.

<to uri="sql-stored:MYFUNC('param1' org.example.Types.INTEGER(10) ${header.srcValue})"/>

URI means that the stored procedure will be called with parameter name "param1", it’s SQL type is read from field INTEGER of class org.example.Types and scale will be set to 10. Input value for the parameter is passed from the header "srcValue".

<to uri="sql-stored:MYFUNC('param1' 100 'mytypename' ${header.srcValue})"/>

URI is identical to previous on except SQL-type is 100 and type name is "mytypename".

Actual call will be done using org.springframework.jdbc.core.SqlParameter.

306.3.2. OUT Parameters

OUT parameters work similarly IN parameters and contain three parts: SQL type(with scale), type name and output parameter name.

SQL type works the same as IN parameters.

Type name is optional and also works the same as IN parameters.

Output parameter name is used for the OUT parameter name, as well as the header name where the result will be stored.

<to uri="sql-stored:MYFUNC(OUT org.example.Types.DECIMAL(10) outheader1)"/>

URI means that OUT parameter’s name is "outheader1" and result will be but into header "outheader1".

<to uri="sql-stored:MYFUNC(OUT org.example.Types.NUMERIC(10) 'mytype' outheader1)"/>

This is identical to previous one but type name will be "mytype".

Actual call will be done using org.springframework.jdbc.core.SqlOutParameter.

306.3.3. INOUT Parameters

INOUT parameters are a combination of all of the above. They receive a value from the exchange, as well as store a result as a message header. The only caveat is that the IN parameter’s "name" is skipped. Instead, the OUT parameter’s "name" defines both the SQL parameter name, as well as the result header name.

<to uri="sql-stored:MYFUNC(INOUT DECIMAL(10) ${headers.inheader} outheader)"/>

Actual call will be done using org.springframework.jdbc.core.SqlInOutParameter.

306.4. Camel Sql Starter

A starter module is available to spring-boot users. When using the starter, the DataSource can be directly configured using spring-boot properties.

# Example for a mysql datasource

To use this feature, add the following dependencies to your spring boot pom.xml file:

    <version>${camel.version}</version> <!-- use the same version as your Camel core version -->


You should also include the specific database driver, if needed.

306.5. See Also

  • Configuring Camel
  • Component
  • Endpoint
  • Getting Started
  • SQL Component