Mehdi Yedes
Mehdi Yedes

Reputation: 2375

Camel SQL component - simple select query result

I'm working with Apache Camel and I've been facing a problem with the sql component. I could only perform an insert query but a simple select query wouldn't return anything. The Datasource is configured properly and I have no errors. I read that the result of a select query is List> but I always have blank results.

Here's my camel route:

from("direct:start")        
    .to("sql:select * from infos where id=1 ?dataSourceRef=myDataSource")
    .beanRef("MBean","monitor")
    .to("log:result");

And here is the method I'm trying to use to process the result:

public Object monitor(Exchange exchange){

    List<Map<String,Object>> l= (List<Map<String,Object>>) exchange.getOut().getBody();
    Map<String,Object> map = l.get(0);
    Object str = map.get("msg");
    exchange.getIn().setBody(str);
    return str;
}

I'm really stuck ..

Upvotes: 1

Views: 6788

Answers (1)

Krishna
Krishna

Reputation: 169

Try this. It worked for me.

public void process(Exchange exchange) throws Exception {
    List<HashMap> out = (ArrayList<HashMap>) exchange.getIn().getBody();

            try{
                for(HashMap outContent:out){
                    String message = outContent.get("output_obj").toString();

                    System.out.println(message);
                }
            }catch(Exception e){
                System.out.println(e);
            }   
}

Upvotes: 1

Related Questions