Search code examples
javajasper-reports

Jasper Reports 6.7.0 generating report is slow


I'm using Jasper Reports 6.7.0 but reports generating so slowly.

I'm generating report for only one record from the database but don't know why I'm getting poor performance.

I've referred some questions from stack overflow but isn't helpful
JasperReports fillReport too slow and resource consuming

I'm using following code on button click to generate report in JavaFX application.

@FXML
private void viewReport(ActionEvent e) {
        Followup followup = followupTable.getSelectionModel().getSelectedItem();
        if (followup != null) {
            int fuRprtId = followup.getFuId();
            try {
                FileInputStream fis = new FileInputStream("src/com/homeo/reports/report1.jrxml");
                BufferedInputStream bis = new BufferedInputStream(fis);
                Map map = new HashMap();
                map.put("fuId", fuRprtId);
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/OPD", "root", "");

                JasperReport jasperReport = (JasperReport) JasperCompileManager.compileReport(bis);
                JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, con);

                JasperViewer.viewReport(jasperPrint, false);
            } catch (SQLException | ClassNotFoundException | FileNotFoundException | JRException ex) {
                Logger.getLogger(FollowUpController.class
                        .getName()).log(Level.SEVERE, null, ex);
            }
        }  

SQL syntax:

SELECT
     followup.`full name` AS followup_full_name,
     followup.`complaints` AS followup_complaints,
     followup.`remedy` AS followup_remedy,
     followup.`fu id` AS followup_fu_id,
     followup.`patientid` AS followup_patientid,
     followup.`date` AS followup_date,
     patient.`age` AS patient_age,
     patient.`address` AS patient_address,
     patient.`ref by` AS patient_ref_by,
     patient.`occupation` AS patient_occupation,
     patient.`diagnosis` AS patient_diagnosis,
     patient.`mother` AS patient_mother,
     patient.`matgrandmother` AS patient_matgrandmother,
     patient.`mat grandfather` AS patient_mat_grandfather,
     patient.`mat uncle` AS patient_mat_uncle,
     patient.`mat aunt` AS patient_mat_aunt,
     patient.`pat uncle` AS patient_pat_uncle,
     patient.`pat aunt` AS patient_pat_aunt,
     patient.`patgrand mother` AS patient_patgrand_mother,
     patient.`pat grandfather` AS patient_pat_grandfather,
     patient.`husband` AS patient_husband,
     patient.`wife` AS patient_wife,
     patient.`children` AS patient_children,
     patient.`brother` AS patient_brother,
     patient.`sister` AS patient_sister,
     patient.`phone` AS patient_phone,
     patient.`gender` AS patient_gender,
     patient.`dob` AS patient_dob,
     patient.`patnt id` AS patient_patnt_id,
     patient.`father` AS patient_father
FROM
     `patient` patient INNER JOIN `followup` followup ON patient.`patnt id` = followup.`patientid` where `fu id` = $P{fuId}  

It is taking approx 8 seconds to load

How to speed up it?

Also report don't load when I build an app


Solution

  • I was curious why it is being slower.
    It was too much slower approx 8 to 9 seconds.

    But I ignored it and go ahead and build as it is but now report was not showing anyway.

    As I had already preferred questions for slowness and wasn't helpful.
    I changed my code and it solved all the problem I have about jasper report.

    I don't recommend following code I guess it is old fashioned and not proper way to do

       FileInputStream fis = new FileInputStream("src/com/homeo/reports/report1.jrxml");
        BufferedInputStream bis = new BufferedInputStream(fis);
        Map map = new HashMap();
        map.put("fuId", fuRprtId);
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/OPD", "root", "");
    
        JasperReport jasperReport = (JasperReport) JasperCompileManager.compileReport(bis);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, con);
    
        JasperViewer.viewReport(jasperPrint, false);
    

    I used following code which is too much faster than above code. Takes approx 2 seconds to load

    try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/OPD", "root", "")) {
        InputStream inputStream = getClass().getResourceAsStream("/com/homeo/reports/report1.jasper");
    
        JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, map, con);
        JasperViewer.viewReport(jasperPrint, false);
        con.close();  
    }
      } catch (SQLException | ClassNotFoundException | JRException ex) {
            Logger.getLogger(FollowUpController.class
                    .getName()).log(Level.SEVERE, null, ex);
    }  
    

    To make above code work properly

    You have to use compiled
    report.jsper instead report.jrfxml
    and use
    "/com/reports/report.jsper" instead "/src/com/reports/report.jsper"