Jasper Reports integration with Rails and MySQL


 I have successfully integrate Jasper Reports with Rails using Oracle database, or Xml data source, but not with MySQL database.

I have been using guide from http://wiki.rubyonrails.org/rails/pages/howtointegratejasperreports to achieve that.

The error that I get when running this report from Rails is 



java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at XmlJasperInterface.report(XmlJasperInterface.java:96)

at XmlJasperInterface.main(XmlJasperInterface.java:67)


In the code below is snippet from my XmlJasperInterface (refer rails wiki) and the error is pointing at the mysql connector driver. I compiled XmlJasperInterface with Netbeans, and I have already added in MySQL JDBC library in my project. The classnotfound error still persists. Anyone has experience in this?


I think this is Java/Jasper problem, not Rails related, that's why I'm posting here.


Thanks :)



  try {
        /* load the required JDBC driver and create the connection
        here JDBC Type Four Driver for MySQL is used*/
        Class.forName("com.mysql.jdbc.Driver"); <<<------------ error
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/myDB","root", "pass");
      //JasperPrint jasperPrint = JasperFillManager.fillReport(compiledDesign, null, new JRXmlDataSource(System.in, selectCriteria));
      JasperPrint jasperPrint = JasperFillManager.fillReport(compiledDesign, params, con);
      if (TYPE_PDF.equals(outputType)) {
        JasperExportManager.exportReportToPdfStream(jasperPrint, System.out);
      else if (TYPE_XML.equals(outputType)) {
        JasperExportManager.exportReportToXmlStream(jasperPrint, System.out);
      else if (TYPE_RTF.equals(outputType)) {
        JRRtfExporter rtfExporter = new JRRtfExporter();
        rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        rtfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, System.out);
      else if (TYPE_XLS.equals(outputType)) {
        JRXlsExporter xlsExporter = new JRXlsExporter();
        xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        xlsExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, System.out);
       // xlsExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
      else if (TYPE_CSV.equals(outputType)) {
        JRCsvExporter csvExporter = new JRCsvExporter();
        csvExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        csvExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, System.out);
      } else {
    } catch (JRException e) {
      return false;
    } catch (Exception e) {
      return false;

Post Edited by themillie at 07/09/2012 07:56
themillie's picture
Joined: Feb 2 2012 - 9:14pm
Last seen: 3 years 10 months ago

0 Answers:

No answers yet