Frage

I'm trying to read .csv file from local directory and insert values into Mysql database. Please suggest me any example using Mulesoft.

War es hilfreich?

Lösung

Inserting CSV into a db:

How to read CSV file and insert data into PostgreSQL using Mule ESB, Mule Studio

Configuring MySQL:

http://blogs.mulesoft.org/working-with-databases-jdbc-in-mule-studio/

If you are reading the file in the middle of a flow, you can use the Requester Module with mulerequester:request instead, like in this example:

https://github.com/mulesoft/mule-module-requester/blob/master/mulerequesterdemo/src/main/app/MuleRequesterDemo.xml

Andere Tipps

I've tried to implement this scenario. But ended up with something else. See if it is helpful to you.

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

you use this flow

<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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top