[[sql-language]]
= SQL Language (deprecated)
:page-source: components/camel-josql/src/main/docs/sql-language.adoc

*Available as of Camel version 1.0*


The SQL support is added by http://josql.sourceforge.net/[JoSQL] and is
primarily used for performing SQL queries on in-memory objects. If you
prefer to perform actual database queries then check out the
xref:jpa-component.adoc[JPA] component.

*Looking for the SQL component*

Camel has both a xref:sql-component.adoc[SQL] language and a
xref:sql-component.adoc[SQL Component]. This page is about the SQL
language. Click on xref:sql-component.adoc[SQL Component] if you are
looking for the component instead.

To use SQL in your camel routes you need to add the a dependency on
*camel-josql* which implements the SQL language.

If you use maven you could just add the following to your pom.xml,
substituting the version number for the latest & greatest release (see
the download page for the latest versions).

[source,xml]
----------------------------------------------------------
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-josql</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>
----------------------------------------------------------

Camel supports http://en.wikipedia.org/wiki/SQL[SQL] to allow an
Expression or Predicate to be
used in the DSL or xref:latest@manual::xml-configuration.adoc[Xml
Configuration]. For example you could use SQL to create an
Predicate in a xref:latest@manual::filter-eip.adoc[Message
Filter] or as an Expression for a
Recipient List.

[source,java]
-----------------------------------------------------------------------
from("queue:foo").setBody().sql("select * from MyType").to("queue:bar")
-----------------------------------------------------------------------

And the spring DSL:

[source,xml]
--------------------------------------
   <from uri="queue:foo"/>
   <setBody>
       <sql>select * from MyType</sql>
   </setBody>
   <to uri="queue:bar"/>
--------------------------------------

== Options


// language options: START
The SQL language supports 1 options, which are listed below.



[width="100%",cols="2,1m,1m,6",options="header"]
|===
| Name | Default | Java Type | Description
| trim | true | Boolean | Whether to trim the value to remove leading and trailing whitespaces and line breaks
|===
// language options: END
// spring-boot-auto-configure options: START
== Spring Boot Auto-Configuration

When using Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

[source,xml]
----
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-josql-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>
----


The component supports 2 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *camel.language.sql.enabled* | Enable sql language | true | Boolean
| *camel.language.sql.trim* | Whether to trim the value to remove leading and trailing whitespaces and line breaks | true | Boolean
|===
// spring-boot-auto-configure options: END

== Loading script from external resource

*Available as of Camel 2.11*

You can externalize the script and have Camel load it from a resource
such as `"classpath:"`, `"file:"`, or `"http:"`.

 This is done using the following syntax: `"resource:scheme:location"`,
eg to refer to a file on the classpath you can do:

[source,java]
----------------------------------------------------------
.setHeader("myHeader").sql("resource:classpath:mysql.sql")
----------------------------------------------------------