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.
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:
'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.
The sample of using:
You can find the full sample of using
JasperViewer
in$jasperreports$\demo\samples\i18n
folder from theJasperReports
distribution package.