如何使用JasperReports API显示报告

时间:2021-02-02 21:05:45

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.

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

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 = "*ersdbv1/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(*ersDBv1View.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
    Logger.getLogger(*ersDBv1View.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
    Logger.getLogger(*ersDBv1View.class.getName()).log(Level.SEVERE, null, ex)
}

1 个解决方案

#1


0  

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的完整示例。

#1


0  

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的完整示例。