0

I have a flow which reads a CSV files and perfrorm CRUD operation in database ... My flow is somewhat like :-

<flow name="CsvToFile" doc:name="CsvToFile">
    <file:inbound-endpoint path="C:\Data" responseTimeout="10000" doc:name="CSV" connector-ref="File">
        <file:filename-wildcard-filter pattern="*.csv" caseSensitive="true"/>
    </file:inbound-endpoint>
    <jdbc-ee:csv-to-maps-transformer delimiter="," mappingFile="src/main/abc.xml" ignoreFirstRecord="true" doc:name="CSVTransformer"/>
    <jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="SelectQuery" queryTimeout="-1" connector-ref="jdbcConnectorGlobal" doc:name="Database">
        <jdbc-ee:query key="SelectQuery" value="Select * FROM DBDATA where ID=#[map-payload:ID]"/>
    </jdbc-ee:outbound-endpoint>
    <set-payload value="#[message.payload]" doc:name="Set Payload"/>
</flow>

Now if I use SELECT SQL statement.. I don't see the result and no data is fetched ... but if I use INSERT like

<jdbc-ee:query key="InsertQuery" value="INSERT INTO DBDATA (ID,NAME,AGE) VALUES(#[map-payload:ID],#[map-payload:NAME],#[map-payload:AGE])"/>

or an UPDATE SQL statement, I can find it's working and data is inserted or updated in dataase.

My question is: how can I read the ID value from .CSV file and use in SELECT query to retrieve values from the database?

2 Answers 2

1

You have exchange-pattern="one-way", meaning the jdbc outbound call will not return to the main flow. Use exchange-pattern="request-response" instead to get a return value.

Also <set-payload value="#[message.payload]" doc:name="Set Payload"/> does not make any sense. You need a transformer of some sort to make the return value readable. You can add a logger to see the returned payload.

UPDATE:

Return value of csv-to-maps-transformer is ArrayList, not Map, so you can not use map-payload:ID. Try splitting the ArrayList, or use #[payload[0].ID] if you have just a single entry.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry ... Actually I have used request-response .. here by mistake I have written one way ... now I have edited ... Now, the issues is Select statement doesn't return data .. where as Insert and Update works fine ... I have used set-payload to get the the payload which I can view it in console .. I can also use logger here .. In case of Insert I have used < set-payload="Successfully Inserted" doc:name="Set Payload" /> which I can see in console and later can be used to save it somewhere else like in a file as a response
Updated the answer, but I am still a bit confused about what you are actually trying to do here.
Thanks ... #[payload[0].ID] is working fine ... yes Select statement returns Array .... But this is returning only first row ... Is there any way I can get all the rows ?? Anyways Thanks for help ..
You will probably have to split the ArrayList, then loop over each item with the query, and aggregate the results. Splitter and Aggregator components, perhaps. You will need to learn to use the Mule routers to do this: mulesoft.org/documentation/display/current/Routers
0

Thanks to Anton.. The final solution is #[payload[0].ID] what I need and working for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.