【问题标题】:Camel SQL component - simple select query resultCamel SQL 组件 - 简单选择查询结果
【发布时间】:2014-06-06 15:27:15
【问题描述】:

我正在使用 Apache Camel,但我一直面临 sql 组件的问题。 我只能执行插入查询,但简单的选择查询不会返回任何内容。 数据源配置正确,我没有错误。 我读到选择查询的结果是 List> 但我总是有空白结果。

这是我的骆驼路线:

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

我真的被困住了..

【问题讨论】:

  • 在您的方法monitor(Exchange ex) 中尝试使用exchange.getIn() 而不是exchange.getOut()
  • 是的,另请参阅此常见问题解答:camel.apache.org/using-getin-or-getout-methods-on-exchange.html
  • 谢谢,我试试。事实上,我暂时切换到使用 jdbc 组件,因为我需要进步,但我会回到那个
  • 还是不行..

标签: sql apache-camel


【解决方案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);
            }   
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 2014-08-16
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多