2.117. SQL
Perform SQL queries.
2.117.1. What’s inside 复制链接链接已复制到粘贴板!
-
SQL component, URI syntax:
sql:query -
SQL Stored Procedure component, URI syntax:
sql-stored:template
Refer to the above links for usage and configuration details.
2.117.2. Maven coordinates 复制链接链接已复制到粘贴板!
Create a new project with this extension on code.camel.redhat.com
Or add the coordinates to your existing project:
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-sql</artifactId>
</dependency>
2.117.3. Additional Camel Quarkus configuration 复制链接链接已复制到粘贴板!
2.117.3.1. Configuring a DataSource 复制链接链接已复制到粘贴板!
This extension leverages Quarkus Agroal for DataSource support. Setting up a DataSource can be achieved via configuration properties.
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=your-username
quarkus.datasource.password=your-password
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/your-database
quarkus.datasource.jdbc.max-size=16
The Camel SQL component will automatically resolve the DataSource bean from the registry. When configuring multiple datasources, you can specify which one is to be used on an SQL endpoint via the URI options datasource or dataSourceRef. Refer to the SQL component documentation for more details.
In dev and test mode you can take advantage of Configuration Free Databases. The Camel SQL component will be automatically configured to use a DataSource that points to a local containerized instance of the database matching the JDBC driver type that you have selected.
2.117.3.2. SQL scripts 复制链接链接已复制到粘贴板!
When configuring sql or sql-stored endpoints to reference script files from the classpath, set the following configuration property to ensure that they are available in native mode.
quarkus.native.resources.includes = queries.sql, sql/*.sql
2.117.3.3. SQL aggregation repository in native mode 复制链接链接已复制到粘贴板!
In order to use SQL aggregation repositories like JdbcAggregationRepository in native mode, you must enable native serialization support.
In addition, if your exchange bodies are custom types, they must be registered for serialization by annotating their class declaration with @RegisterForReflection(serialization = true).