I've been developing an accounting software by JAVA on NetBeans 7.3 IDE.
I used Jasper Report (iReport) to produce reports in my application. I needed to get specific data which I populate to JTable
and get only those data to Jasper Report. So, I used JRTableModelDataSource
to generate data on Jasper report.
Nevertheless, I failed, that means, when I click on 'show Report' button tt doesn't show anything and it shows an error on NetBeans IDE Log window as,
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:151)
at accdat.frmJournalBatchList.btnNewActionPerformed(frmJournalBatchList.java:395)
at accdat.frmJournalBatchList.access$400(frmJournalBatchList.java:38)
at accdat.frmJournalBatchList$5.actionPerformed(frmJournalBatchList.java:117)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at org.jvnet.substance.utils.RolloverButtonListener.mouseReleased(RolloverButtonListener.java:109)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 41 more
BUILD SUCCESSFUL (total time: 29 seconds)
I used following codes to populate jTable.
private void GetGLData(){
try
{
con = ConnectionManagerACCDAT.getConnection();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery("SELECT * FROM gl_bt_lst ORDER BY BT_NO ASC" );
DefaultTableModel dtm = (DefaultTableModel) tblJournalBatchList.getModel();
Object[] values = new Object[5];
while (rs.next()) {
values = new Object[5];
values[0] = rs.getString("BT_NO");
values[1] = rs.getString("DT");
values[2] = rs.getString("DSCRP");
values[3] = rs.getString("RD_2_PST");
values[4] = rs.getString("PSTTD");
dtm.addRow(values);
}
// Close the connection after use
rs.close();
stmt.close();
con.close();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e, "Journal Batch List.", JOptionPane.ERROR_MESSAGE);
}
}
and I used following codes to generate report.
private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {
try
{
String ReportSource = "D:/Reports/Test.jrxml";
if (new File(ReportSource).exists() == false)
{
JOptionPane.showMessageDialog(null,"Please go to setting and Choose report Source");
return;
}
JasperReport jasperReport = JasperCompileManager.compileReport(ReportSource);
Map params = new HashMap();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
params, new JRTableModelDataSource(tblJournalBatchList.getModel()));
JasperViewer.viewReport(jasperPrint, false);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e,"reports Error ",JOptionPane.ERROR_MESSAGE);
}
// TODO add your handling code here:
}
Guys, where's the wrong thing that i have done. BTW, I have imported relevant Libraries to NetBeans and Used Fields Name as COLUMN_1,COLUMN_2... ect... to link report to jTable Columns.
Plese include follwing common jar files in the classpth for general web application with jasper reports
- commons-logging-1.0.4.jar
- commons-digester-1.7.jar
- commons-collections-2.1.1.jar
- iText-2.1.7.jar
- poi-3.5-FINAL-20090928.jar
- jasperreports-3.7.3.jar