Search code examples
apache-camelcamel-sql

Camel Endpoint URI using sql containing date range


I specified an endpoint containing a URI for a sql component as:

<endpoint id="select-myS" uri="sql:select myField from myView where ChangeDate between :#startDate and :#endDate"/>

I am setting startDate and endDate as headers. In that case I receive the error message as: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'between'

If I try to avoid between, and add two clauses as below: ChangeDate >= :#startDate and ChangeDate <= :#endDate, I receive other error: The value of attribute "uri" associated with an element type "null" must not contain the '<' character

(I also tried :#endDate>=ChangeDate , and it also not work! :-( ).

Could you please advise on this?

Thank you!


Solution

  • As you're using XML to describe your route and endpoints, you have to escape your '>' and '<'chars, eg:

    > should be escaped as &gt; (aka greather than)
    < should be escaped as &lt; (aka lower than)
    

    Which gives:

    <endpoint uri="sql:... where ChangeDate &gt;= :#startDate and ChangeDate &lt;= :#endDate">