读取.csv文件并在mulesoft中将值插入MySQL数据库

时间:2014-04-29 11:31:19

标签: mysql database mule mule-studio

我试图从本地目录读取.csv文件并将值插入Mysql数据库。请建议我使用Mulesoft的任何示例。

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

我已尝试实施此方案。但最终得到了别的东西。看看它对你有帮助。

 <flow name="WriteToDB">
    <file:inbound-endpoint path="${file_path}" moveToPattern="#[StringUtils.substringBeforeLast(message.inboundProperties.originalFilename,&quot;.txt&quot;)].bkp" moveToDirectory="${file_path}" connector-ref="FileRead" pollingFrequency="30000" responseTimeout="10000" doc:name="File">
        <file:filename-regex-filter pattern=".*\.txt$" caseSensitive="true"/>
    </file:inbound-endpoint>
    <object-to-string-transformer doc:name="Object to String"/>
    <logger message="Starting Split--------#[StringUtils.substringBeforeLast(message.inboundProperties.originalFilename,&quot;.txt&quot;)].bkp  ----#[message.inboundProperties.originalFilename]" level="INFO" doc:name="Logger"/>
    <splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter"/>
    <expression-component doc:name="Expression"><![CDATA[#[StringUtils.split(message.payload, '\n\r')]]]></expression-component>
    <logger message="Split done #[message.payload]" level="INFO" doc:name="Logger"/>
</flow>

答案 2 :(得分:0)

你使用这个流程

<flow name="apdev-americanFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/flights" 
doc:name="HTTP"/>
    <db:select config-ref="MySQL_Configuration" doc:name="Database">
        <db:parameterized-query><![CDATA[SELECT *
FROM american]]></db:parameterized-query>
    </db:select>
    <dw:transform-message doc:name="Transform Message" 
metadata:id="6aa1324d-4ae4-4a42-9aeb-18da081f5cb1">
        <dw:input-payload doc:sample="sample_data\list_map.dwl"/>
        <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> {
ID: payload01.ID,
code: payload01.code1 ++ payload01.code2,
price: payload01.price as :number,
departureDate: payload01.takeOffDate as :string,
destination: payload01.toAirport,
emptySeats: payload01.seatsAvailable as :number,
plane: {
    type: payload01.planeType,
    totalSeats: payload01.totalSeats as :number
}
})]]></dw:set-payload>
    </dw:transform-message>
</flow>