Calling MSSQL stored procedures from 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',
开发者_如何学Go'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?
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.
精彩评论