---
title: "Mule ESB 开发实例数据库篇之数据表查询"
author: "teabo"
date: "2015-03-06T13:55:38Z"
tags: []
categories: ["开源软件"]
slug: "mule-esb"
draft: false
lastmod: "2015-03-06T13:55:17Z"
id: 2189354
url: "https://teabo.iteye.com/blog/2189354"
---

## [**1.****简介**]()

这个例子使用mule连接数据查询数据，通过HTTP请求将查询到的数据转为json格式展示到前端。

## **2.**   **例子**

下面是查询数据库的例子，如下图所示。

![](http://note.youdao.com/yws/api/group/7000793/noteresource/EF23189A5F354F1284B1235F85914A64/version/66?method=get-resource)

                                图 1

## **3.**   **配置**

#### 3.1.  流程的配置

![](http://note.youdao.com/yws/api/group/7000793/noteresource/34CE21DFE95B416FB2809045D68CC9A1/version/64?method=get-resource)

                图 2

#### 3.2.  数据库的配置

![](http://note.youdao.com/yws/api/group/7000793/noteresource/F9D7E36147684AA1BBD7D2243FFFCD53/version/65?method=get-resource)

                                        图 3

 

图 3的参数解释如下：

**Parameter**

**Value**

**Display Name**

流程图上数据库显示的名称

**Config Reference**

用到的数据库连接器

**Operation**

查询操作

**Query Type**

传递参数进行查询

**Parameterized SQL Statement**

SELECT NAME,AUTHOR  FROM SYS\_MENU\_INFO where id = #\[message.inboundProperties\['id']]

 

 

连接oracle数据库如下图所示：

 

![](http://note.youdao.com/yws/api/group/7000793/noteresource/CD47DC969EA848CDBE85CE8BC11681B6/version/67?method=get-resource)

                                    图 4

 

图 4的参数解释如下：

**Parameter**

**Value**

**Name**

数据库的配置名称

**Host**

连接主机的IP

**Port**

数据库的端口号

**User**

用户名

**Password**

密码

**Database**

Not set (defined in **URL**)

**Configure via Spring bean**

No (unchecked)

**DataSource Reference**

None

**URL**

连接数据库的URL

**Enable DataSense**

True (default)

 

## **4.**   **整个流程的代码如下所示**

&lt;db:oracle-config name="Oracle\_Configuration" host="192.168.2.20"

  port="1521" instance="orcl" user="mshare\_center1" password="sunshine"

  doc:name="Oracle Configuration" /&gt;

 

 &lt;flow name="test2Flow1"&gt;

  &lt;http:inbound-endpoint exchange-pattern="request-response"

   host="localhost" port="8081" doc:name="HTTP" /&gt;

  &lt;db:select config-ref="Oracle\_Configuration" doc:name="Database"

   doc:description="test"&gt;

            &lt;db:parameterized-query&gt;&lt;!\[CDATA\[SELECT NAME,AUTHOR  FROM SYS\_MENU\_INFO where id = #\[message.inboundProperties\['id']]]]&gt;&lt;/db:parameterized-query&gt;

  &lt;/db:select&gt;

  &lt;json:object-to-json-transformer

   doc:name="Object to JSON" /&gt;

 &lt;/flow&gt;