简体   繁体   English

Mule:JDBC选择不适用于#[variable]值

[英]Mule:JDBC Select not working with #[variable] value

I have this piece of code in my configuration where I am using a variable as part of the 'WHERE' clause to retrieve some values from a database. 我的配置中有这段代码,其中我使用变量作为“ WHERE”子句的一部分,以从数据库中检索一些值。

    <logger message="ZIP CODE:#[zipcode] " level="INFO" doc:name="Logger"></logger>
    <jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryTimeout="-1" 
     connector-ref="Database" doc:name="Get Information" queryKey="Select MKT">
    <jdbc-ee:query key="Select MKT" value="SELECT PRIMARY,SECONDARY FROM MKT 
     WHERE  MRZIP=#[zipcode]"/>
    </jdbc-ee:outbound-endpoint> 
    <logger message="VALUES Selected for MKTREL : #[message.payload]" 
    level="INFO" doc:name="logger"></logger> 

This line does not give the output as in there are no results coming back from the DB. 这行没有给出输出,因为没有结果从数据库返回。

    ZIP CODE:59718 
    INFO  2014-02-11 14:58:19,057 [[salesorderservice].SalesOrderProcess_pickOut.stage1.02]     
    INFO  2014-02-11 14:58:19,093 [[salesorderservice].SalesOrderProcess_pickOut.stage1.02]  
    : VALUES Selected for MKTREL : []

However when I hardcode the value I get the correct result: 但是,当我对值进行硬编码时,会得到正确的结果:

    <jdbc-ee:query key="Select MKT" value="SELECT PRIMARY,SECONDARY FROM MKT 
     WHERE  MRZIP=59718"/>

Output is: 输出为:

    VALUES Selected for MKTREL : [{PRIMARY=76, SECONDARY=45}]

Am I missing something here? 我在这里想念什么吗?

-S -S

Try setting the zipcode variable to Integer, or use WHERE MRZIP=#[Integer.parseInt(zipcode)] . 尝试将邮政编码变量设置为Integer,或使用WHERE MRZIP=#[Integer.parseInt(zipcode)] I guess you have an issue with your database not liking quoted integers. 我想您的数据库不喜欢用引号引起来的整数存在问题。

Try to cast value in query to number by using DB specific function. 尝试使用特定于数据库的函数将查询中的值转换为数字。

eg ORACLE/PLSQL and TO_NUMBER function: 例如ORACLE / PLSQL和TO_NUMBER函数:

<jdbc-ee:query
    key="Select MKT"
    value="SELECT PRIMARY,SECONDARY FROM MKT WHERE  MRZIP=TO_NUMBER(#[zipcode])"
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM