1. Home
  2. ...
  3. Data Sources
  4. Data Source Binding

Data Source Binding

Binding data sources to integration flows

After creating a new data source, you must link it to the integration flow where it will be used.

To do this, follow the steps below:

Access or create the flow to which the data source will be linked.

TIP

If you haven't created a flow yet, go to: Creating a Source type integration.

Click Add Step and then select the Components tab.

Use one of the components below to link a data source to your integration flow, depending on the type of operation you want to execute. Read the details of each component and use cases in the following table:

Component
Use Case
Query
SQL (Recommended)Dynamic queries (SELECTs) that use parameters from headers or body. Ideal for externalizing queries.In the component itself (e.g., uri: sql:classpath:query.sql)
JDBCDirect operations (INSERT, UPDATE) where the query is built in a previous flow step.The query must be in the message body at the time of the call.
SQL Stored ProcedureExecute complex business logic that already exists in the database (e.g., GET_USERS_BY_LASTNAME).In the component itself (e.g., uri: sql-stored:PROCEDURE_NAME(...))

Select the component and click CONFIRM or drag it to the diagram. The configuration form will open automatically.

With the configuration form open, locate the Data Source Name or Data Source fields and select, from the dropdown list, the name of the data source you registered.

  • For JDBC, select the data source name in the Data Source Name field.
  • For SQL and SQL Stored Procedure, select the data source name in the Data Source field.
WARNING

If a component (JDBC, SQL, or SQL Procedure) linked to a data source is deleted, the link between the data source and the flow will be automatically removed. This prevents the data source from being associated with a non-existent component. Similarly, if a flow linked to a data source is deleted, all links associated with that flow will be automatically removed.

Fill in the remaining form fields (such as the query or procedure name). See the parameters for each component.

Complete the configuration by clicking CONFIRM.

Components

TIP

Click on the component names to access the official Apache Camel documentation.

SQL is ideal for dynamic queries, where parameters are passed through headers or body, and the query can be externalized.

Parameters

Parameter (UI)
Parameter (YAML)
Required
Description
Example
Data Source Nameparameters.dataSourceYesThe exact name of the Data Source you created.datasource-mysql-2
SQL Queryuri (path)YesThe query to be executed. It's recommended to use classpath: to reference a .sql file or constant: for simple queries.sql:classpath:query.sql
Query Parameters(in query)NoPlaceholders in your query (e.g., :#userLastName) that are replaced by Camel headers.WHERE lastname = :#userLastName

Example

  • The flow receives an HTTP POST request at the /test endpoint. The request body must contain the lastName field.

  • Then, it uses the value obtained from lastName to create a header called userLastName, extracting the value with jsonpath ($.lastName).

  • Next, it executes an SQL query defined in the query.sql file (referenced via classpath), using the data source named datasource-mysql-2.

  • Finally, it converts (marshals) the SQL query result to JSON format, preparing the response to be sent to the client.

In summary: this flow receives a POST with a last name (lastName), executes an SQL query using that value, and returns the result in JSON.

See below the content of the query.sql file used in the flow above:

SQL Query:

The query.sql file is stored in Resources and referenced via classpath. It contains the following SQL query:

SELECT id, name FROM newTestes.users WHERE lastname = :#userLastName.

This query will return all records from the users table whose last name (lastname) is "Doe", showing only the id and name fields. Read more about SQL instructions here.

Below are the request and response bodies:

Request Body:

Response Body:

JDBC

JDBC is used for more direct operations. The main difference is that it expects the SQL query to be in the message body at the time the component is called.

Parameters

Parameter (UI)
Parameter (YAML)
Required
Description
Example
Data Sourceuri (prefix)YesThe Data Source name preceded by jdbc:.jdbc:datasource-mysql-2
SQL Query(implicit)YesThere is no query field. You must use a previous step (like setBody) to set the message body as the query string.setBody -> constant: SELECT ...

Example

  • The flow receives an HTTP POST request at the /test endpoint.

  • Then, it sets the message body as a constant string: SELECT id, name FROM newTestes.users WHERE lastname = 'Wilson'. In other words, it creates a fixed SQL query, fetching all users with the last name "Wilson".

  • Next, it executes the above query on the database using the datasource-mysql-2 data source, through the JDBC component.

  • Finally, it converts (marshals) the query result to JSON format, preparing the response to be sent to the client.

In summary: this flow always executes the same SQL query (fetching users with the last name "Wilson") and returns the result in JSON.

SQL Stored Procedure

SQL Stored Procedure is optimized for calling stored procedures in the database.

Parameters

Parameter (UI)
Parameter (YAML)
Required
Description
Example
Data Sourceparameters.dataSourceYesThe exact name of the Data Source you created.datasource-mysql-5
Procedure Nameuri (path)YesThe name of the procedure to be called, followed by its parameters.sql-stored:GET_USERS_BY_LASTNAME(...)
Parameter Mapping(in uri)NoDefines how Camel headers are mapped to procedure parameters.(VARCHAR ${header.searchlastName})

Example

  • The flow receives an HTTP POST request at the /test-stored-procedure endpoint.

  • Then it sets a header called searchLastName with the constant value "Doe".

  • Next, it calls the stored procedure GET_USERS_BY_LASTNAME, passing the value of the searchLastName header as a parameter (VARCHAR ${header.searchLastName}). The component used is SQL Stored Procedure, which executes procedures in the database.

  • Then, it uses the datasource-mysql-5 data source to connect to the database.

  • Finally, it converts the procedure result to JSON.

In summary: the flow executes a stored procedure in MySQL, passing a parameter, and returns the result in JSON.

Below are the procedure definition and response body:

Procedure created in MySQL database:

This procedure called GET_USERS_BY_LASTNAME, created in MySQL, receives an input parameter called p_lastname (of type VARCHAR).

When executed, it performs a query on the users table, fetching all records whose lastname field equals the value received in p_lastname. The query result returns the id, name, and lastname fields of those users.

In summary, the procedure returns all users who have the last name provided as a parameter.

Response Body

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more