【问题标题】:How to access flow vars in jdbc end point in mule studio application如何在 mule studio 应用程序中访问 jdbc 端点中的流变量
【发布时间】:2015-08-09 05:19:06
【问题描述】:
<jdbc-ee:mysql-data-source name="MySQL_Data_Source" user="root" password="root" url="jdbc:mysql://localhost:3306/test" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"/>
<jdbc-ee:connector name="test" dataSource-ref="MySQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<data-mapper:config name="DataMapper" transformationGraphPath="mapper.grf" doc:name="DataMapper"/>
<flow name="EmployeeListFlow1" doc:name="EmployeeListFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="employeelist"/>
    <json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Map"/>
    <choice doc:name="Choice">
        <when expression="payload.storeId == null || payload.storeId &lt;= 0 ">
            <set-variable variableName="query" value="select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where companyid = #[message.payload.companyId]" doc:name="CompanyId"/>
        </when>
        <otherwise>
            <set-variable variableName="query" value="select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where employeeid in (select employeeid from employeestores where storeid =#[message.payload.storeId] )" doc:name="StoreId"/>
        </otherwise>
    </choice>
    <jdbc-ee:outbound-endpoint exchange-pattern="request-response"  queryTimeout="-1" doc:name="EmployeeListFetch" connector-ref="Theatro" queryKey="employees_list">
        <jdbc-ee:query key="employees_list" value="#[flowVars['query']]"/>
    </jdbc-ee:outbound-endpoint>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>

例外:

根异常堆栈跟踪: java.lang.IllegalArgumentException:没有为 SQL 语句找到 SQL 策略:#[flowVars['query']] 在 com.mulesoft.mule.transport.jdbc.sqlstrategy.EESqlStatementStrategyFactory.create(EESqlStatementStrategyFactory.java:109) 在 org.mule.transport.jdbc.JdbcMessageDispatcher.doSend(JdbcMessageDispatcher.java:69) 在 org.mule.transport.AbstractMessageDispatcher.process(AbstractMessageDispatcher.java:81) + 3 个以上(设置调试级别日志记录或 '-Dmule.verbose.exceptions=true' 为所有内容)

这里我想根据输入动态构建jdbc查询。

json 数据 {"companyId":"1","storeId":"1"} 请帮帮我。

【问题讨论】:

  • 你有没有尝试过?
  • 没有。我只尝试使用此代码

标签: mule


【解决方案1】:

尝试对 jdbc 动态出站端点使用类似以下内容:

<outbound-endpoint address="jdbc://select * from ${datasource.table} #[variable:where-statement]" exchange-pattern="request-response"/>

HTH

【讨论】:

    【解决方案2】:

    这里有两个错误,
    在选择中缺少表达式[]
    类似&lt;when expression="[payload.storeId == null || payload.storeId &amp;lt;= 0] "&gt;
    接下来你的查询应该是这样的:-

    select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where employeeid in (select employeeid from employeestores where storeid ='#[message.payload.storeId]' )  
    

    #[message.payload.storeId] 应该在 '' 内,因为 storeId 是一个字符串

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多