You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by abdes <ae...@gmail.com> on 2009/08/06 19:09:15 UTC

dynamic sql request

Hi,
i have diffficult to pass parameter from exchange content to SQL request :
here my code :

exchange content :
<Listes>
<Liste>
  <id>123456</id>
</Liste>
<Liste>
  <id>123456</id>
</Liste>
<Listes>


from("jms:q_in")
.enrich("direct:resource", new ExampleAggregationStrategy())
.to("direct:result");
			
		
		
from("direct:resource")
.setBody(constant("SELECT * FROM v_test WHERE indv =XXXX"))

That i want, is to pass <Listes><Liste><id>  value to indv parameter.
How can i process ?

Regards


-- 
View this message in context: http://www.nabble.com/dynamic-sql-request-tp24850692p24850692.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: dynamic sql request

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Aug 7, 2009 at 12:45 PM, Roman
Kalukiewicz<ro...@gmail.com> wrote:
> You can also use SQL component this way:
>
> from("jms:q_in")
> .transform(XPathBuilder.xpath("/Listes/Liste/id").stringResult())
> .to("sql:SELECT * FROM v_test WHERE indv=#")
> .to("somewhere else");
>

Cool maybe we/you should add that as an example to the SQL component wiki page

> Roman
>
> 2009/8/7 Claus Ibsen <cl...@gmail.com>:
>> On Thu, Aug 6, 2009 at 7:09 PM, abdes<ae...@gmail.com> wrote:
>>>
>>> Hi,
>>> i have diffficult to pass parameter from exchange content to SQL request :
>>> here my code :
>>>
>>> exchange content :
>>> <Listes>
>>> <Liste>
>>>  <id>123456</id>
>>> </Liste>
>>> <Liste>
>>>  <id>123456</id>
>>> </Liste>
>>> <Listes>
>>>
>>>
>>> from("jms:q_in")
>>> .enrich("direct:resource", new ExampleAggregationStrategy())
>>> .to("direct:result");
>>>
>>>
>>>
>>> from("direct:resource")
>>> .setBody(constant("SELECT * FROM v_test WHERE indv =XXXX"))
>>>
>>> That i want, is to pass <Listes><Liste><id>  value to indv parameter.
>>> How can i process ?
>>>
>>
>> The XML above is that content from the JMS message?
>>
>> Do you need the XML afterwards or only need to grab the <id> tag?
>>
>> You can use XPath to select the XML node of choice. But also use a
>> POJO to fetch it?
>> In the POJO you can even set the result as the SQL statement directly
>>
>> For starters you can use a plain Processor that is a bit low level but
>> gives you power in regular Java code to work with it.
>>
>> To get the data as XML you can use
>>
>> Document doc = exchange.getIn().getBody(Document.class);
>>
>> from(jms)
>> process(new MyIdToSQLProcessor())
>> .to("jdbc:myDatasource")
>> .to("somewhereelse");
>>
>>
>>
>> And in relation to the constant language. Camel provides a bit more
>> powerful the simple language that allows you to build strings dynamic
>> http://camel.apache.org/simple.html
>>
>> And then there are all the others with a real programming language underneath
>> http://camel.apache.org/languages.html
>>
>>
>>> Regards
>>>
>>>
>>> --
>>> View this message in context: http://www.nabble.com/dynamic-sql-request-tp24850692p24850692.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: dynamic sql request

Posted by Roman Kalukiewicz <ro...@gmail.com>.
You can also use SQL component this way:

from("jms:q_in")
.transform(XPathBuilder.xpath("/Listes/Liste/id").stringResult())
.to("sql:SELECT * FROM v_test WHERE indv=#")
.to("somewhere else");

Roman

2009/8/7 Claus Ibsen <cl...@gmail.com>:
> On Thu, Aug 6, 2009 at 7:09 PM, abdes<ae...@gmail.com> wrote:
>>
>> Hi,
>> i have diffficult to pass parameter from exchange content to SQL request :
>> here my code :
>>
>> exchange content :
>> <Listes>
>> <Liste>
>>  <id>123456</id>
>> </Liste>
>> <Liste>
>>  <id>123456</id>
>> </Liste>
>> <Listes>
>>
>>
>> from("jms:q_in")
>> .enrich("direct:resource", new ExampleAggregationStrategy())
>> .to("direct:result");
>>
>>
>>
>> from("direct:resource")
>> .setBody(constant("SELECT * FROM v_test WHERE indv =XXXX"))
>>
>> That i want, is to pass <Listes><Liste><id>  value to indv parameter.
>> How can i process ?
>>
>
> The XML above is that content from the JMS message?
>
> Do you need the XML afterwards or only need to grab the <id> tag?
>
> You can use XPath to select the XML node of choice. But also use a
> POJO to fetch it?
> In the POJO you can even set the result as the SQL statement directly
>
> For starters you can use a plain Processor that is a bit low level but
> gives you power in regular Java code to work with it.
>
> To get the data as XML you can use
>
> Document doc = exchange.getIn().getBody(Document.class);
>
> from(jms)
> process(new MyIdToSQLProcessor())
> .to("jdbc:myDatasource")
> .to("somewhereelse");
>
>
>
> And in relation to the constant language. Camel provides a bit more
> powerful the simple language that allows you to build strings dynamic
> http://camel.apache.org/simple.html
>
> And then there are all the others with a real programming language underneath
> http://camel.apache.org/languages.html
>
>
>> Regards
>>
>>
>> --
>> View this message in context: http://www.nabble.com/dynamic-sql-request-tp24850692p24850692.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>

Re: dynamic sql request

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Aug 6, 2009 at 7:09 PM, abdes<ae...@gmail.com> wrote:
>
> Hi,
> i have diffficult to pass parameter from exchange content to SQL request :
> here my code :
>
> exchange content :
> <Listes>
> <Liste>
>  <id>123456</id>
> </Liste>
> <Liste>
>  <id>123456</id>
> </Liste>
> <Listes>
>
>
> from("jms:q_in")
> .enrich("direct:resource", new ExampleAggregationStrategy())
> .to("direct:result");
>
>
>
> from("direct:resource")
> .setBody(constant("SELECT * FROM v_test WHERE indv =XXXX"))
>
> That i want, is to pass <Listes><Liste><id>  value to indv parameter.
> How can i process ?
>

The XML above is that content from the JMS message?

Do you need the XML afterwards or only need to grab the <id> tag?

You can use XPath to select the XML node of choice. But also use a
POJO to fetch it?
In the POJO you can even set the result as the SQL statement directly

For starters you can use a plain Processor that is a bit low level but
gives you power in regular Java code to work with it.

To get the data as XML you can use

Document doc = exchange.getIn().getBody(Document.class);

from(jms)
process(new MyIdToSQLProcessor())
.to("jdbc:myDatasource")
.to("somewhereelse");



And in relation to the constant language. Camel provides a bit more
powerful the simple language that allows you to build strings dynamic
http://camel.apache.org/simple.html

And then there are all the others with a real programming language underneath
http://camel.apache.org/languages.html


> Regards
>
>
> --
> View this message in context: http://www.nabble.com/dynamic-sql-request-tp24850692p24850692.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus