如何将Date作为参数传递给jasper报告 [英] How to pass Date as parameter to jasper report

查看:166
本文介绍了如何将Date作为参数传递给jasper报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建 JR 报告,该报告将start_date和end_date作为参数。

I am trying to create JR report which is taking start_date and end_date as parameters.

查询:

SELECT * FROM emp WHERE joining_date BETWEEN $P{frm_date} AND $P{to_date}

代码:

Date from_date = dt_from_date.getDate();
Date to_date = dt_to_date.getDate();
java.sql.Date frm_dte = new java.sql.Date(from_date.getTime());
java.sql.Date to_dte = new java.sql.Date(to_date.getTime());
try {
    HashMap map = new HashMap();
    map.put("$P{frm_date}", frm_dte);
    map.put("$P{to_date}", to_dte);
    JasperPrint jp = JasperFillManager.fillReport(is, map, con);
    JRViewer jv = new JRViewer(jp);
    JFrame jf = new JFrame();
    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);
    jf.setSize(new Dimension(800, 600));
    jf.setLocation(300, 100);
    jf.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
} catch (JRException ex) {
    ex.printStackTrace();
}

我们可以将两个参数传递给表中的同一列吗?例如:

Can we pass Two Parameters to same Column in the table? Eg:

map.put("joining_date", frm_dte); 
map.put("joining_date", to_dte);


推荐答案

您的代码错误。

你应该传递如下参数:

Map<String, Object> map = new HashMap<String, Object>();
map.put("frm_date", frm_dte);
map.put("to_date", to_dte);

您无需添加 P $ {} 到参数的名称。

You don't need to add P${} to the parameter's name.

中有很多样本> JasperReports 分发包。

你可以看看此示例了解更多详情。

You can look at this sample for more details.

这篇关于如何将Date作为参数传递给jasper报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆