从 iReport 调用 MSSQL 存储过程

发布于 2024-11-29 23:37:13 字数 1105 浏览 1 评论 0原文

我想从 iReport 调用 MSSQL 服务器中的存储过程。

查询:

SET QUOTED_IDENTIFIER OFF 
SET DATEFORMAT mdy 

Exec SP_SAMPLE '12-jan-2008', '12-jul-2011', 
"$P!{Param1}", 
"$P!{Param2}", 
1, 
"$P!{Param3}" 

SET QUOTED_IDENTIFIER ON
Where, 
    Param1 = 'A436F3A9-6A8B-40C4-B38E-567B05522449',
        '4DD40BC2-3390-4B1B-8841-        483A8FDAB2FD',
        'B95E8F04-6EE7-4BC6-BDD0-F95C4AFDAC0B',
        'AE757961-0E25-41B8-A382-    7600DDA0ABC7',
        '90B9CC0C-6090-4CEF-8BC9-9C8EA3C0F63C',
        '1E191B19-13D0-4CE2-B1EC-    3CFF9316887F',
        'A9EE7AE9-435C-4164-96F5-3DB20A6321BE',
        'DCD6D045-8B42-4B83-8C97-21EE9DFF644C'
    Param2 = '4E6E8464-F08A-4BB8-950F-38908E4E7B30',
        '76EBA40E-F898-4541-9208-8A6B3A35E082',
        '7C64DA92-C168-4A74-8955-F1974258AD12',
        '2E6DDC25-E037-4842-9E7F-2B9586561744'
    Param3 = 3EC43FB7-F258-4441-8188-A55E7BD40ADE 

请注意,存储过程param1param2param3在sqlserver中是文本数据类型。而在 iReport 中我将它们作为一个集合。

谁能告诉我如何在 iReport 中生成上述带双引号的查询?

另外,运行 iReport 时有没有办法显示带有填充参数值的查询?

I want to call an stored procedure in an MSSQL server from iReport.

Query:

SET QUOTED_IDENTIFIER OFF 
SET DATEFORMAT mdy 

Exec SP_SAMPLE '12-jan-2008', '12-jul-2011', 
"$P!{Param1}", 
"$P!{Param2}", 
1, 
"$P!{Param3}" 

SET QUOTED_IDENTIFIER ON
Where, 
    Param1 = 'A436F3A9-6A8B-40C4-B38E-567B05522449',
        '4DD40BC2-3390-4B1B-8841-        483A8FDAB2FD',
        'B95E8F04-6EE7-4BC6-BDD0-F95C4AFDAC0B',
        'AE757961-0E25-41B8-A382-    7600DDA0ABC7',
        '90B9CC0C-6090-4CEF-8BC9-9C8EA3C0F63C',
        '1E191B19-13D0-4CE2-B1EC-    3CFF9316887F',
        'A9EE7AE9-435C-4164-96F5-3DB20A6321BE',
        'DCD6D045-8B42-4B83-8C97-21EE9DFF644C'
    Param2 = '4E6E8464-F08A-4BB8-950F-38908E4E7B30',
        '76EBA40E-F898-4541-9208-8A6B3A35E082',
        '7C64DA92-C168-4A74-8955-F1974258AD12',
        '2E6DDC25-E037-4842-9E7F-2B9586561744'
    Param3 = 3EC43FB7-F258-4441-8188-A55E7BD40ADE 

Note that stored procedures param1, param2, param3 are of text datatype in sqlserver. Whereas in iReport I made them a collection.

Could any one tell me how can I generate the above query in iReport with the double quotes?

Also, Is there any way to display the query with filled parameter values when running iReport?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2024-12-06 23:37:13

Jasper Reports 使用两种类型的参数进行操作:$P{name_parameter} 和 $P!{name_parameter}。
你用的是$P!查询中的参数使您可以完全控制构建查询。

示例:

<parameter name="strParam1" class="java.lang.String"/>
<parameter name="strParam2" class="java.lang.String"/>
<parameter name="strParam3" class="java.lang.String"/>
<queryString><![CDATA[SELECT atr1 FROM mytable WHERE stratr1=$P{strParam1} AND stratr2=$P!{strParam2} AND stratr3=$P!{strParam3}]]></queryString>

如果:

strParam1 =  string1 // (without quotes)
strParam2 = 'string2' // param (with quotes)
strParam3 =  string3 // (without quotes)

查询结果将是:

SELECT atr1 FROM mytable WHERE stratr1='string1' AND stratr2='string2' AND stratr3=string3

另外,有没有办法显示带有填充参数的查询
运行 iReport 时的值?

在 IReport 4.1 中,您可以在输出控制台(iReport 输出窗口)中查看结果查询。

您可以设置 log4j.properties 以查看自定义 java 应用程序的结果查询。

Jasper Reports operates with two types of parameters: $P{name_parameter} and $P!{name_parameter}.
You using $P! parameter in query that give you full control on building query.

Example:

<parameter name="strParam1" class="java.lang.String"/>
<parameter name="strParam2" class="java.lang.String"/>
<parameter name="strParam3" class="java.lang.String"/>
<queryString><![CDATA[SELECT atr1 FROM mytable WHERE stratr1=$P{strParam1} AND stratr2=$P!{strParam2} AND stratr3=$P!{strParam3}]]></queryString>

If:

strParam1 =  string1 // (without quotes)
strParam2 = 'string2' // param (with quotes)
strParam3 =  string3 // (without quotes)

the result query will be:

SELECT atr1 FROM mytable WHERE stratr1='string1' AND stratr2='string2' AND stratr3=string3

Also, Is there any way to display the query with filled parameter
values when running iReport?

In IReport 4.1 you can view resulting query in output console (iReport output window).

You can set log4j.properties to see result query for custom java application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文