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

时间:2012-09-09 15:35:17

标签: java mysql jasper-reports

我正在尝试使用Java将数据传递给JasperReport。但是,表数据非常动态,我无法将SQL查询传递给报表。对此有何看法? 我有一个对象类型的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);
    }

1 个答案:

答案 0 :(得分:0)

@(Html.Kendo().Grid<Models.MCMessageCenter>()
    .Name("myMessagesGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.Id);
        columns.Bound(c => c.MessageTitle);
        columns.Bound(c => c.CreatedDate)
            .ClientTemplate("#= kendo.toString(kendo.parseDate(CreatedDate), 'yyyy-MM-dd') #")
            .ClientGroupHeaderTemplate("#= kendo.toString(kendo.parseDate(value), 'yyyy-MM-dd') #");
    })
    .Scrollable()
    .Groupable()
    .Sortable()
    .Pageable(p => p
        .Refresh(true)
        .PageSizes(new int[] { 20, 50, 100 })
        .ButtonCount(5)
    )
    .DataSource(ds => ds
        .Ajax()
        .Model(mdl => mdl.Field(x => x.CreatedDate.Date))
        .Group(g => g.Add(c => c.CreatedDate))
        .Sort(s => s.Add(c => c.CreatedDate).Descending())
        .Read(r => r.Action("MyMessagesRead", "Message"))
    )
)