Summary: Reference for the pfx-sql Camel component — database operations (select, insert, upsert, delete, truncate) for external SQL databases.
URI Format
pfx-sql:method?param=value
Producer only (no consumer). Used to read from or write to external SQL databases.
Available Methods
|
Method |
Description |
|---|---|
|
|
Execute SQL query and return results |
|
|
Execute SQL query with batched iteration (for large datasets) |
|
|
Insert data into a table |
|
|
Insert or update data based on business keys |
|
|
Delete records matching a filter |
|
|
Remove all data from a table |
URI Parameters
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
String |
|
Name of the Spring DataSource bean |
|
|
String |
|
Target database table |
|
|
String |
|
Mapper ID for field transformation |
|
|
Integer |
|
Batch size for database fetch |
|
|
Boolean |
|
Enable batch mode for select |
|
|
SQLDialect |
|
SQL dialect (MYSQL, ORACLE, DERBY, POSTGRESQL, SNOWFLAKE) |
|
|
String |
|
SQL query for select operations |
|
|
String |
|
Comma-separated business key columns for upsert |
|
|
String |
|
Where to store results: |
|
|
String |
|
Name of the header/property for output |
|
|
String |
|
Filter reference for delete operations |
Common Patterns
Select Data from Database
<route id="selectFromDb">
<from uri="timer://dbFetch?repeatCount=1"/>
<to uri="pfx-sql:select?sql=SELECT * FROM products WHERE active = 1&dataSource=myDb&dialect=MYSQL"/>
<to uri="pfx-api:loaddata?objectType=P&mapper=productMapper"/>
</route>
Batched Select (Large Datasets)
<route id="batchedSelectFromDb">
<from uri="timer://dbFetch?repeatCount=1"/>
<to uri="pfx-sql:selectIterator?sql=SELECT * FROM products&dataSource=myDb&batchSize=5000"/>
<split>
<simple>${body}</simple>
<to uri="pfx-api:loaddata?objectType=P&mapper=productMapper"/>
</split>
</route>
Insert/Upsert to Database
<route id="exportToDb">
<from uri="timer://export?repeatCount=1"/>
<to uri="pfx-api:fetch?objectType=P&filter=allProducts"/>
<to uri="pfx-sql:upsert?table=products&mapper=dbMapper&businessKeys=sku&dataSource=myDb"/>
</route>
Truncate Table
<to uri="pfx-sql:truncate?table=staging_products&dataSource=myDb"/>
Delete with Filter
<to uri="pfx-sql:delete?table=products&filter=inactiveFilter&dataSource=myDb"/>
DataSource Configuration
Define the DataSource bean in your Spring context or application.properties:
# Example: MySQL DataSource
spring.datasource.url=jdbc:mysql://{{db.host}}:3306/{{db.name}}
spring.datasource.username={{db.username}}
spring.datasource.password={{db.password}}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
For multiple databases, define named DataSource beans and reference them with the dataSource parameter.
SQL Dialects
|
Dialect |
Database |
|---|---|
|
|
MySQL (default) |
|
|
Oracle |
|
|
Apache Derby |
|
|
PostgreSQL |
|
|
Snowflake |