简体   繁体   English

如何使用JasperReports API显示报告

[英]How to show report with JasperReports API

I am using NetBeans 7 and developing java database application. 我正在使用NetBeans 7并开发Java数据库应用程序。 For the reporting purpose I have installed the iReport 4 plug-in in NetBeans 7 and designed the very simple report of my application. 为了进行报告,我在NetBeans 7安装了iReport 4插件,并设计了应用程序的非常简单的报告。 How can I call the report through a button call. 如何通过按钮调用报告。

Few days later of this question what i have done is: 此问题几天后,我做了什么:

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: 我下载了JAR文件并将其添加到Netbeans之后,我在一个按钮中进行了以下编码,但是当我单击该按钮时,出现了此错误:

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

And this is is the code which i have done on a button event click: 这是我在按钮事件单击上完成的代码:

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)
}

For viewing report with help of JasperReports API you can use the net.sf.jasperreports.view.JasperViewer class. 要在JasperReports API的帮助下查看报告,可以使用net.sf.jasperreports.view.JasperViewer类。

The sample of using: 使用示例:

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

You can find the full sample of using JasperViewer in $jasperreports$\\demo\\samples\\i18n folder from the JasperReports distribution package. 您可以从JasperReports分发包的$jasperreports$\\demo\\samples\\i18n JasperViewer $jasperreports$\\demo\\samples\\i18n文件夹中找到使用JasperViewer的完整示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM