【发布时间】:2019-10-15 07:25:51
【问题描述】:
我正在使用 Jasper Reports 6.7.0,但报告生成速度很慢。
我只为数据库中的一条记录生成报告,但不知道为什么性能不佳。
我提到了一些堆栈溢出的问题,但没有帮助
JasperReports fillReport too slow and resource consuming
我在单击按钮时使用以下代码在 JavaFX 应用程序中生成报告。
@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 秒
如何加快速度?
还报告在我构建应用时不加载
【问题讨论】:
-
你能监控到底是哪一步慢吗?例如。它可能是你的 SQL
-
@Swapnil:要检查慢速是否取决于您的 SQL 查询,您可以编写一个更简单的查询(没有连接或只有一行)并检查填写报告的时间。跨度>
-
如果不想使用JOIN,则必须对后续表的每个字段使用子查询,但性能代价更高。如果您的 JOIN 很慢,请检查您是否在相关表上添加了正确的索引
-
您使用的是哪个 DBMS?
标签: java jasper-reports