问题描述
我想使用数据库连接器为同一数据库的3个表选择和插入查询。我想知道是有一个替代品或如何使用1数据库连接器来完成?
I want to write select and insert queries for 3 tables for the same database using a database connector. I want to know is there a alternative or how can it be done using 1 database connector?
我最终使用5个数据库连接器。但我认为这使流程看起来很复杂。是否有其他方法。
I ended up using 5 database connector. But I think this makes the flow look complicated. Is there any other way of doing this.
推荐答案
它可以通过一个DB连接器执行3个不同的操作来实现。
请阅读文档: -
You are going in a wrong way :)
It can be achieved by a single DB connector performing 3 different operations.
Pls go through the documentation here :- https://docs.mulesoft.com/mule-user-guide/v/3.8/database-connector
您需要定义连接您的db的单个全局数据库连接器: -
You need to define single global db connector that connects your db :-
<db:generic-config name="GlobalDB_Config" url="jdbc:sqlserver://${mssql.server}:${mssql.port};databaseName=${mssql.database};user=${mssql.user};password=${mssql.password}" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" doc:name="Generic Database Configuration"/>
,然后可以使用不同的数据库在流中执行不同的操作(选择,插入,更新等)组件引用相同的全局db连接器: -
and then you can perform different operations (select, insert, update etc) in your flow using different db component referring to the same global db connector :-
<db:insert config-ref="GlobalDB_Config">
<db:parameterized-query>INSERT INTO TABLE1(POSITION, NAME) VALUES (777, #[payload])</db:parameterized-query>
</db:insert>
或
<db:select config-ref="GlobalDB_Config">
<db:parameterized-query><![CDATA[SELECT POSITION from TABLE1 WHERE NAME = '#[message.inboundProperties['NAME']]></db:parameterized-query>
</db:select>
这篇关于在Mule中的数据库连接器中编写多个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!