如何使用mule 3.4.2调用MySQL存储过程。我是Mule的新手,项目团队正在使用3.4.2版本

时间:2015-04-17 08:36:49

标签: mysql mule

我试图调用一个mysql存储过程,它将使用mule返回字符串值。我是骡子的新手,我使用的是Mule 3.4.2企业版。

我的配置代码是:

<jdbc-ee:mysql-data-source name="MySQL_Data_Source"
    user="root" password="root" url="jdbc:mysql://localhost:3306/MULE_POC"
    transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"></jdbc-ee:mysql-data-source>
<jdbc-ee:connector name="Database" dataSource-ref="MySQL_Data_Source"
    validateConnections="true" queryTimeout="-1" pollingFrequency="0"
    doc:name="Database"></jdbc-ee:connector>
<data-mapper:config name="map_to_csv"
    transformationGraphPath="map_to_csv.grf" doc:name="map_to_csv"></data-mapper:config>

<flow name="stored_procedure_pocFlow1" doc:name="stored_procedure_pocFlow1">
    <http:inbound-endpoint exchange-pattern="request-response"
        host="localhost" port="4566" doc:name="HTTP" path="mani"></http:inbound-endpoint>
    <logger level="INFO" doc:name="Logger"></logger>
    <jdbc-ee:outbound-endpoint exchange-pattern="request-response"
        connector-ref="Database" doc:name="Database">

        <jdbc-ee:query key="Query"
            value="call GET_HIGH_GENDER('2015-04-16', @HIGHEST_GENDER) "></jdbc-ee:query>

        <db-stored-procedure config-ref="Database">
            <db-parameterized-query>{ call GET_HIGH_GENDER(:JOINING_DATE,
                :HIGHEST_GENDER) }</db-parameterized-query>
            <db-in-param name="JOINING_DATE" value="'2015-04-16'"></db-in-param>
            <db-out-param name="result"></db-out-param>
        </db-stored-procedure>

    </jdbc-ee:outbound-endpoint>

    <data-mapper:transform config-ref="map_to_csv"
        doc:name="Map To CSV"></data-mapper:transform>
    <object-to-string-transformer doc:name="Object to String"></object-to-string-transformer>

    <logger message="#[payload:]" level="INFO" doc:name="Logger"></logger>
</flow>

请帮帮我......谢谢。我收到如下错误消息:

Failed to route event via endpoint:
DefaultOutboundEndpoint{endpointUri=jdbc://Query, connector=EEJdbcConnector
    {
  name=Database
  lifecycle=start
  this=18474a2
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=true
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
,  name='endpoint.jdbc.Query', mep=REQUEST_RESPONSE, properties={queryTimeout=-1, queries=merged: {Query=call GET_HIGH_GENDER('2015-04-16', @HIGHEST_GENDER) }}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: String

2 个答案:

答案 0 :(得分:0)

你为什么使用

<db-stored-procedure config-ref="Database">
        <db-parameterized-query>{ call GET_HIGH_GENDER(:JOINING_DATE,
            :HIGHEST_GENDER) }</db-parameterized-query>
        <db-in-param name="JOINING_DATE" value="'2015-04-16'"></db-in-param>
        <db-out-param name="result"></db-out-param>
    </db-stored-procedure>

Mule 3.5 Db 组件? 如果您使用 Mule 3.4 ,则只需使用

即可
<jdbc-ee:outbound-endpoint exchange-pattern="request-response"  connector-ref="Database" doc:name="Database">
 <jdbc-ee:query key="Query" value="CALL GET_HIGH_GENDER('2015-04-16'; @HIGHEST_GENDER) "></jdbc-ee:query>
</jdbc-ee:outbound-endpoint>

使用调用 exec 方法调用存储过程。 通常通话将用于调用存储过程

答案 1 :(得分:0)

感谢@Anirban的帮助。它现在正在工作。正确的是

<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="Query" connector-ref="Database" doc:name="Database"> 
            <jdbc-ee:query key="Query" value="CALL GET_HIGH_GENDER_STRING(#['2015-04-16';String;in], #[HIGHEST_GENDER;string;out]) "></jdbc-ee:query>  
        </jdbc-ee:outbound-endpoint>