2014-04-22 40 views
1

我正在使用Apache Camel,並且我一直面臨着sql組件的問題。 我只能執行插入查詢,但一個簡單的選擇查詢不會返回任何東西。 數據源配置正確,我沒有錯誤。 我讀到,選擇查詢的結果是列表>但我總是有空白的結果。駱駝SQL組件 - 簡單的選擇查詢結果

這裏是我的駱駝航線:

from("direct:start")   
    .to("sql:select * from infos where id=1 ?dataSourceRef=myDataSource") 
    .beanRef("MBean","monitor") 
    .to("log: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; 
} 

我真的卡住..

+0

在你的方法'monitor(Exchange ex)'嘗試使用'exchange.getIn()'而不是'exchange.getOut()'。 – Ralf

+0

是的,另請參閱此FAQ:http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html –

+0

謝謝我會試試它。 事實上,我切換到使用jdbc組件的時刻,因爲我需要進步,但我會回到 – midihenry

回答

1

嘗試這個。它爲我工作。

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); 
      } 
}