Summary: Insert data into an external SQL database table.
URI Format
pfx-sql:insert?table=myTable&dataSource=myDb
Parameters
|
Parameter |
Type |
Default |
Required |
Description |
|---|---|---|---|---|
|
|
String |
|
No |
Name of the Spring DataSource bean |
|
|
String |
|
Yes |
Target database table |
|
|
String |
|
No |
Mapper ID for field transformation |
|
|
String |
|
No |
Comma-separated business key columns (used for deduplication before insert) |
|
|
SQLDialect |
|
No |
SQL dialect |
|
|
Integer |
|
No |
Batch size for database writes |
Examples
Basic Insert
<route id="insertToDb">
<from uri="timer://export?repeatCount=1"/>
<to uri="pfx-api:fetch?objectType=P&filter=allProducts"/>
<to uri="pfx-sql:insert?table=products&dataSource=myDb"/>
</route>
Insert with Mapper
<route id="insertWithMapper">
<from uri="timer://export?repeatCount=1"/>
<to uri="pfx-api:fetch?objectType=P&filter=allProducts"/>
<to uri="pfx-sql:insert?table=products&mapper=dbMapper&dataSource=myDb"/>
</route>
Insert with Business Keys (Deduplication)
<route id="insertDedup">
<from uri="timer://export?repeatCount=1"/>
<to uri="pfx-api:fetch?objectType=P"/>
<to uri="pfx-sql:insert?table=products&businessKeys=sku&dataSource=myDb"/>
</route>
Common Pitfalls
|
Problem |
Cause |
Fix |
|---|---|---|
|
|
Missing required parameter |
Add |
|
Duplicate key errors |
Table has unique constraints and data has duplicates |
Use |
|
Column mismatch |
Body fields don't match table columns |
Use a |
|
Wrong dialect |
Default is MYSQL but target is different |
Set |
See Also
-
pfx-sql Component — Parent reference
-
pfx-sql:upsert — Insert or update by business key