How to Extract the value of resultSet returned from JDBC response (Via MEL) Mule ESB

我只是一个虾纸丫 提交于 2019-12-11 21:36:56

问题


I have JDBC where I'm calling the stored Procedure, It is returning the response as below, But I'm pretty not sure how to extract the value of result set

Please find the response from DB

{updateCount1=4,resultSet1=[{XML_F5RYI-11YTR=<Customers><Customer1>John<Customer1><Customer2>Ganesh<Customer2><Customers>}],resultSet2[{SequenceNumber=94}],updateCount2=1, updateCount3=4}

I have used the this expression #[message.payload.get(0)], It has return the ResultSet as below, But not exactly value required. I need to take the xml value of XML_F5RYI-11YTR.

{XML_F5RYI-11YTR=<Customers><Customer1>John<Customer1><Customer2>Ganesh<Customer2><Customers>}

Also tried like below #[message.payload.get(0).XML_F5RYI-11YTR] but getting error , not able to extract the xml.

Could you please suggest how can I extract the xml from the ResultSet1


回答1:


In most cases, the way you did it should work. I think what is happening here is that the hyphen in the column name is interpreted by the MEL parser as a subtraction. So you could change yours to this syntax, and it should work:

#[message.payload.get(0)['XML_F5RYI-11YTR']]

Also you can omit "message", as payload is resolvable directly:

#[payload.get(0)['XML_F5RYI-11YTR']]

You could use array bracket syntax to access the first row in the result set, instead of the get method:

#[payload[0]['XML_F5RYI-11YTR']]

Finally, you might want to do something for each row returned from the database. If you use a collection-splitter or a for-each, your payload will be the map that represents the row, instead of a list of maps representing the whole result set:

<collection-splitter />
<logger message="#[payload['XML_F5RYI-11YTR']]" />

EDIT

To access the result set in the payload shown in the question, you would need to access it like so:

#[payload.resultSet1[0]['XML_F5RYI-11YTR']]



回答2:


The database connector gives you a list of maps. The map keys will be the name of the columns. Therefore if you want to get updateCount1, you can use something like this:

#[payload.get('updateCount1')]"



回答3:


Thump rule - you database connector gives you list of map, not sure what format does it is carry, if you want XML_F5RYI.. value then do the below

[message.payload.get(0)] convert it to json or map from which #[message.payload.get("XML_F5RYI-11YTR")]



来源:https://stackoverflow.com/questions/28526065/how-to-extract-the-value-of-resultset-returned-from-jdbc-response-via-mel-mule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!