开发者

Passing a variable and query to Jasper report

Is it possible to pass both an SQL qu开发者_StackOverflow中文版ery, e.g. (<![CDATA[$P!{SQL}]]>), and a variable $V as parameters to a Jasper report at the same time?

Also, how can I pass the variable $V to my Jasper report using Java?


Often it is desired to just transform some parameter in order to use it in a query (in this case, the following works :) ).

E.g. (pseudo code - Groovy syntax!)

parameter:

filtParamUserName = "foo"

"variable" (technically not: in this case another parameter following it)1:

sqlCondUserName = $P{filtParamUserName} ? " and user_name = '$P{filtParamUserName}'" : ""

thus you could easily use it in your query like:

select * from bar where 1=1 $P{sqlCondUserName}

1: you have to set the Default Value Expression of the sqlCondUserName and Is For Prompting = false


A variable is something that varies during the report generation, like the number of pages for example. So a variable ($V) is not something you can pass to a report. You may pass any value from your Java code to the report as a parameter ($P), though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜