我正在尝试使用 Java 将数据传递给 JasperReport。但是,表数据非常动态,我无法将 SQL 查询传递给报表。有什么想法吗?我有一个对象类型的二维数组,其中包含所有数据。我怎么能通过呢?
ConnectionManager con = new ConnectionManager();
con.establishConnection();
String fileName = "Pmc_Bill.jrxml";
String outFileName = "OutputReport.pdf";
HashMap params = new HashMap();
params.put("PName", pname);
params.put("PSerial", psrl);
params.put("PGender",pgen);
params.put("PPhone",pph);
params.put("PAge",page);
params.put("PRefer",pref);
params.put("PDateR",dateNow);
try {
JasperReport jasperReport = JasperCompileManager.compileReport(fileName);
if(jasperReport != null )
System.out.println("so far so good ");
// Fill the report using an empty data source
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JRTableModelDataSource(tbl.getModel()));//con.connection);
try{
JasperExportManager.exportReportToPdfFile(jasperPrint, outFileName);
System.out.printf("File exported sucessfully");
}catch(Exception e){
e.printStackTrace();
}
JasperViewer.viewReport(jasperPrint);
} catch (JRException e) {
JOptionPane.showMessageDialog(null, e);
e.printStackTrace();
System.exit(1);
}