如何使用JasperReports API显示报告 [英] How to show report with JasperReports API

查看:240
本文介绍了如何使用JasperReports API显示报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NetBeans 7 并开发java数据库应用程序。出于报告目的,我在 NetBeans 7 中安装了 iReport 4 插件,并设计了我的非常简单的报告应用。如何通过按钮调用来调用报告。

I am using NetBeans 7 and developing java database application. For the reporting purpose I have installed the iReport 4 plug-in in NetBeans 7 and designed the very simple report of my application. How can I call the report through a button call.

此问题的几天后我所做的是:

我下载了JAR文件并将其添加到Netbeans之后我在按钮中进行了以下编码,但是当我点击按钮时它会出现此错误:

I downloaded the JAR file and added it to the Netbeans after that i did the following coding in a button but as i click the button it gives this error:


'Exception in thread "AWT-EventQueue-0"     java.lang.Error:'java.lang.reflect.InvocationTargetException'


这就是我所做的代码按钮事件点击:

try {
    String reportName = "prisonersdbv1/reports/newReport.jasper";
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/APD", "root", "khan");
    JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), conn);
    JasperViewer jv = new JasperViewer(jasperPrint);
    jv.setVisible(true);
} catch (JRException ex) {
    Logger.getLogger(PrisonersDBv1View.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
    Logger.getLogger(PrisonersDBv1View.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
    Logger.getLogger(PrisonersDBv1View.class.getName()).log(Level.SEVERE, null, ex)
}


推荐答案

JasperReports API 您可以使用 net.sf.jasperreports.view.JasperViewer class。

For viewing report with help of JasperReports API you can use the net.sf.jasperreports.view.JasperViewer class.

使用样本:

JasperViewer.viewReport("sampleReport.jrprint", false, true, locale); 

您可以找到使用 JasperViewer的完整示例来自 $ jasperreports $ \demo\samples\i18n 文件夹中的 JasperReports 发行包。

You can find the full sample of using JasperViewer in $jasperreports$\demo\samples\i18n folder from the JasperReports distribution package.

这篇关于如何使用JasperReports API显示报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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