Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java在Jasper报表表中添加数据_Java_Mysql_Jasper Reports - Fatal编程技术网

如何使用Java在Jasper报表表中添加数据

如何使用Java在Jasper报表表中添加数据,java,mysql,jasper-reports,Java,Mysql,Jasper Reports,我正在尝试使用Java将数据传递到JasperReport。但是,表数据是非常动态的,我无法将SQL查询传递给报表。有什么想法吗? 我有一个object类型的2D数组,其中包含所有数据。我怎么能通过呢 ConnectionManager con = new ConnectionManager(); con.establishConnection(); String fileName = "Pmc_Bill.jrxml"; String outFileName = "Ou

我正在尝试使用Java将数据传递到JasperReport。但是,表数据是非常动态的,我无法将SQL查询传递给报表。有什么想法吗? 我有一个object类型的2D数组,其中包含所有数据。我怎么能通过呢

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);
    }
“表数据是非常动态的,不能通过sql查询”是什么意思?如果您的数据保存在数据库中,您仍然需要一个查询。您可以阅读文章。数据源的JRMapArrayDataSource、JRMapCollectionDataSource、ListOfArrayDataSource、JRBeanArrayDataSource、JRBeanCollectionDataSource实现是代码的理想候选。
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList);
Map parameters = new HashMap();
parameters.put("ParameterName", "Value Wanna Pass");
parameters.put("Other Parameter", Data source Name For Filling the table);

        JasperReport report = (JasperReport)JRLoader.loadObject("Path for the Jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());