我在NetBeans 7.3 IDE上开发了JAVA的会计软件。
我使用Jasper Report(iReport)在我的应用程序中生成报告。我需要获取我填充到JTable
的特定数据,并仅将这些数据提供给Jasper Report。因此,我使用JRTableModelDataSource
生成有关Jasper报告的数据。
尽管如此,我失败了,这意味着,当我点击“显示报告”时button tt不显示任何内容,它在NetBeans IDE Log窗口中显示错误,
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)
我使用以下代码填充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);
}
}
我使用以下代码生成报告。
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:
}
伙计们,我做错了什么。顺便说一句,我已将相关的库导入NetBeans,将已使用的字段名称导入为COLUMN_1,COLUMN_2 ...等,以将报告链接到jTable列。
答案 0 :(得分:1)
请注意在一般Web应用程序的classpth中包含常见的jar文件 与jasper报告
- 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
醇>