我试图从本地目录读取.csv文件并将值插入Mysql数据库。请建议我使用Mulesoft的任何示例。
答案 0 :(得分:1)
将CSV插入数据库:
How to read CSV file and insert data into PostgreSQL using Mule ESB, Mule Studio
配置MySQL:
http://blogs.mulesoft.org/working-with-databases-jdbc-in-mule-studio/
如果您正在流程中间阅读文件,则可以使用mulerequester:request
代替请求者模块,如下例所示:
答案 1 :(得分:0)
我已尝试实施此方案。但最终得到了别的东西。看看它对你有帮助。
<flow name="WriteToDB">
<file:inbound-endpoint path="${file_path}" moveToPattern="#[StringUtils.substringBeforeLast(message.inboundProperties.originalFilename,".txt")].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,".txt")].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>