简体   繁体   English

Mirth:数据库读取器,如何处理sql查询返回的[多行]?

[英]Mirth : database reader, how to deal with [multiple rows] returned from sql query?

I am new to Mirth connect and I need some help 我是Mirth Connect的新手,需要帮助

I am working on a demo like the following: 我正在进行如下演示:

the source is Database Reader the destination is a Document writer 源是数据库阅读器 ,目标是文档编写器

The SQL select query in the source returns multiple rows "and this is what I need" I am trying to generate a pdf document [ the document writer ] which contains the values of all returned columns but Actually , what is written in the file is the last returned row ONLY 源中的SQL select查询返回多行“这就是我需要的”我试图生成一个pdf文档[文档编写器],其中包含所有返回列的值,但实际上,写在文件中的是最后返回的行

this is the HTML template I wrote 这是我写的HTML模板

<html>
<head></head>

<body>
<div>
${Target_path}\\${fileName}
</div>

</body>
</html>

and in the destination , I have transformers of type Mapping which maps the values of the returned columns to string 在目标位置,我有Mapping类型的转换器,该转换器将返回的列的值映射到string

The SQL statement selects two columns from my database , both are strings SQL语句从数据库中选择两列,都是列

the first column represents a path , and the second column represents a file name So I have many file names returned from the sql statement and I need to write all of them to this document 第一列代表路径,第二列代表文件名,所以我从sql语句返回了许多文件名,我需要将所有文件名都写到该文档中

Any hints about how can I deal with every row returned from the query? 关于如何处理查询返回的每一行的任何提示?

Best Regards, 最好的祝福,

I'm using JavaScript instead to pull my data but you can format your entries beforehand and insert them into an ArrayList. 我使用JavaScript提取数据,但是您可以预先格式化条目并将其插入ArrayList。 From there, map the list to a channel map variable. 从那里,将列表映射到频道映射变量。

var dbConn;
var result;
var entryList = java.util.ArrayList();

try {
    dbConn = DatabaseConnectionFactory.createDatabaseConnection('DRIVER', 'ADDRESS', 'USERNAME', 'PASSWORD');
    result = dbConn.executeCachedQuery('YOUR QUERY');
    while (result.next()) {
        var entry = result.getString(1) + "//" + result.getString(2);
        list.add(entry);
    }
} finally {
    if (dbConn) {
        dbConn.close();
    }
}

channelMap.put('entryList', entryList);

In your template, you can use Velocity in your html template to dynamically create your PDF like so. 在您的模板中,您可以像这样在HTML模板中使用Velocity来动态创建PDF。

<html>
    <head/>
    <body>
        #foreach ($entry in ${entryList})
        <div>
            $entry
        </div>
        #end
    </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM