Mule:如何将Array参数发送到DB Update(Mule: how to send Array parameter to DB Update)

编程入门 行业动态 更新时间:2024-10-27 18:30:19
Mule:如何将Array参数发送到DB Update(Mule: how to send Array parameter to DB Update)

我有一个PG表,其字段类型为char(10)[]。

我需要使用Mule流中的值更新表中的记录。

所以,我做了这样的事情:

flowVars.test=['aaa', 'bbb',ccc'];

然后,我正在尝试提交这样的更新语句:

update tab1 set fld1=#[flowVars.test]

它失败了,错误:

Cannot cast an instance of java.util.ArrayList to type Types.ARRAY

我的理解是在这种情况下应该使用SQL数组,但我无法弄清楚如何在流中获取这样一个数组的实例以及如何在MEL中使用它。

有人可以建议吗?

谢谢,

I have a PG table with a field of type char(10)[].

I need to update a record in the table with values from a Mule flow.

So, i did something like this:

flowVars.test=['aaa', 'bbb',ccc'];

Then, I'm trying to submit an update statement like this:

update tab1 set fld1=#[flowVars.test]

it's failing with the error:

Cannot cast an instance of java.util.ArrayList to type Types.ARRAY

My understanding is that SQL array should be used in this scenario but I can't figure out how to get an instance of such an array in a flow and how to work with it in MEL.

Can someone please advise?

Thank you,

最满意答案

有许多消息来源建议使用Connection#createArrayOf() 。 但我不知道如何在数据库连接器中使用它。

但是,为此我会做这个解决方案:

将ArrayList转换为String。 它应该形成为: {value1, value2, ...} 将数据库查询类型从参数化更改为动态 更新SQL查询成为: update tab1 set fld1 = '#[flowVars.test]' 。 此查询类型需要额外的单引号。

最后,通过使用以下配置,我可以更新字符类型(10)[]的字段:

<expression-transformer expression="#[flowVars.test = ['aaa', 'bbb', 'ccc'].toString().replace('[', '{').replace(']', '}')]" doc:name="Expression"/> <db:update config-ref="Postgre_Database_Configuration" doc:name="Database"> <db:dynamic-query><![CDATA[update tab1 set fld1 = '#[flowVars.test]']]></db:dynamic-query> </db:update>

Ok, I've found an answer in MuleSoft doc. Starting from version 3.6 DB connector supports custom types and allows defining mapping between SQL arrays and structures and custom user classes. It's documented here .

更多推荐

本文发布于:2023-08-05 04:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   如何将   参数   Array   Mule

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!