Jasper Reports 6.7.0生成报告的速度很慢 [英] Jasper Reports 6.7.0 generating report is slow

查看:71
本文介绍了Jasper Reports 6.7.0生成报告的速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jasper Reports 6.7.0 ,但是报告生成速度非常慢.

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.

我从堆栈溢出中提到了一些问题,但没有帮助
JasperReports fillReport太慢且消耗资源

我在单击按钮时使用以下代码来在JavaFX应用程序中生成报告.

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语法:

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}  

加载大约需要8秒钟

It is taking approx 8 seconds to load

如何加快速度?

在构建应用程序时,报告也不会加载

Also report don't load when I build an app

推荐答案

我很好奇为什么它变慢了.
大约8到9秒太慢了.

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.

因为我已经很喜欢 slowness 的问题,所以没有帮助.
我更改了代码,它解决了有关Jasper Report的所有问题.

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);

我使用了下面的代码,它比上面的代码快得多.大约需要 2秒加载

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

您必须使用已编译的
report.jsper 代替 report.jrfxml
并使用
"/com/reports/report.jsper" 代替"/src/com/reports/report.jsper"

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

这篇关于Jasper Reports 6.7.0生成报告的速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆