将报告参数绑定到sql输出jasper报告

时间:2015-11-30 13:51:35

标签: jasper-reports

我有一个现有的报告,需要稍加修改。假设我的报告查询类似于

select name,currency,productcode from  where name=?

现在这个'?'值将来自报告参数say countryName。这可以使用参数化查询来完成而不是问题。 现在我需要的是这个参数countryName来从另一个查询中获取数据,如下面的

select name from countries

简而言之,我想将报告参数countryName的值绑定到上述查询的输出中,并且我还想将此查询放在报告中。 使用birt非常容易,但我想知道是否可以使用jasper?

P.S我是jasper报告中的新手。

我试图用一个小方案来表示我的问题。实际报告远不止于此,而且非常复杂。 任何帮助将非常感谢!!

1 个答案:

答案 0 :(得分:0)

我给出答案如何在不通过参数图传递任何东西的情况下实现这一点(即使我认为参数图应该是首选方式,修改标准模块以支持参数图)

你说你的国家名称会有组合框值,我们需要让它保持静态。 (或者有一种静态的方式来访问它,“只能有一个”)

界面的示例类

package com.your.package;

public class SelectCountryInterface {

  private static JComboBox<String> selectCountry;

  public static synchronized String getSelectedCountry(){
    Object value = selectCountry.getSelectedItem();
    if (value instanceof String){
        return (String)value;
    }
    return "";
  }

  //...Here goes you code to instance and populate the combobox
}

jasper报告(。jrxml)

  1. 定义一个参数并将defaultValueExpression设置为指向类中的静态方法,这样它将使用您从接口类提供的值进行初始化。

    <parameter name="country" class="java.lang.String" isForPrompting="false">
      <defaultValueExpression><![CDATA[com.your.package.SelectCountryInterface.getSelectedCountry()]]> </defaultValueExpression>
    </parameter>
    
  2. 设置queryString以使用您的参数

    <queryString>
       <![CDATA[select name,currency,productcode from  where name=$P{country}]]>
    </queryString>
    
相关问题