how to add data in Table of Jasper Report using Java

Posted by Areeb Gillani on Stack Overflow See other posts from Stack Overflow or by Areeb Gillani
Published on 2012-09-09T15:35:16Z Indexed on 2012/09/09 15:38 UTC
Read the original article Hit count: 171

Filed under:
|
|

i am here to ask you just a simple question that i am trying to pass data to a jasper report using java but i dont know how to to, because the table data is very dynamic thats y cannot pass sql query. any idea for this. i have a 2D array of object type, where i have all the data... so how can i pass that... Thanx in advance...!:)

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

© Stack Overflow or respective owner

Related posts about java

Related posts about mysql