我创建了一个示例报告,并尝试从jFrame按钮单击加载它。
代码:
try {
String IP = "192.168.1.123";
String DataBase = "traders_bikri";
String ID = "root";
String Password = "PASSWORD";
Connection con1 = DriverManager.getConnection("jdbc:mysql://" + IP + "/" + DataBase + "", ID, Password);
String report = "N:\\projectTest\\src\\projectTest\\report1.jasper";
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
JOptionPane.showMessageDialog(null, ex);
}
JasperReport jr = JasperCompileManager.compileReport(report);
JasperPrint jp = JasperFillManager.fillReport(jr, null, con1);
JasperViewer.viewReport(jp, false);
con1.close();
} catch (JRException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
} catch (SQLException ex) {
Logger.getLogger(ReportLoaderForm.class.getName()).log(Level.SEVERE, null, ex);
}
这是来自输出窗口。
run:
Sat Jul 22 20:25:36 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:81)
at net.sf.jasperreports.engine.JRPropertiesUtil.loadProperties(JRPropertiesUtil.java:102)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.initProperties(DefaultJasperReportsContext.java:99)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.<init>(DefaultJasperReportsContext.java:76)
at net.sf.jasperreports.engine.DefaultJasperReportsContext.<clinit>(DefaultJasperReportsContext.java:59)
at net.sf.jasperreports.engine.JasperCompileManager.getDefaultInstance(JasperCompileManager.java:200)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:575)
at ireportsdemo.ReportLoaderForm.jButton1ActionPerformed(ReportLoaderForm.java:96)
at ireportsdemo.ReportLoaderForm.access$000(ReportLoaderForm.java:25)
at ireportsdemo.ReportLoaderForm$1.actionPerformed(ReportLoaderForm.java:50)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
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 java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 46 more
请指导找出问题所在。 此外,当我在iReports设计和预览中预览报表时,它在IDE和Internet Explorer中都能很好地加载。
我不得不两次使用try-catch块,因为我强迫我这样做。