• jasper2


    package jasper;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import net.sf.jasperreports.engine.JRException;
    import net.sf.jasperreports.engine.JRExporter;
    import net.sf.jasperreports.engine.JRExporterParameter;
    import net.sf.jasperreports.engine.JasperExportManager;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
    import net.sf.jasperreports.engine.export.JRPdfExporter;
    import net.sf.jasperreports.engine.export.JRXlsExporter;

    public class JasperReportFill {
    @SuppressWarnings("unchecked")
    private static String dbdriver="org.gjt.mm.mysql.Driver";
    private static String dburl="jdbc:mysql://localhost:3306/mldn";
    private static String dbuser="root";
    private static String dbpwd="admin";
    public static void main(String[] args) throws Exception {
    Class.forName(dbdriver);
    Connection con=DriverManager.getConnection(dburl, dbuser, dbpwd);
    String sourceFileName1 = "f://jaspertest/report1.jasper";
    String sourceFileName2 = "f://jaspertest/report2.jasper";
    String sourceFileName3 = "f://jaspertest/report3.jasper";
    String printFileName = null;
    // DataBeanList DataBeanList = new DataBeanList();
    //ArrayList dataList = DataBeanList.getDataBeanList();
    //JRBeanCollectionDataSource beanColDataSource =
    // new JRBeanCollectionDataSource(dataList);

    Map parameters = new HashMap();

    try {
    JasperPrint print1 = JasperFillManager.fillReport(sourceFileName1,
    parameters,con);
    JasperPrint print2 = JasperFillManager.fillReport(sourceFileName2,
    parameters,con);
    JasperPrint print3 = JasperFillManager.fillReport(sourceFileName3,
    parameters,con);
    List printList=new ArrayList();
    printList.add(print1);
    printList.add(print3);
    printList.add(print2);
    JRExporter exporter=new JRPdfExporter();
    File reportFile = new File("f://jaspertest/demo.pdf");
    OutputStream ouputStream = new FileOutputStream(reportFile);
    exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"f://demo.pdf");
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
    exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,printList);

    exporter.exportReport();
    } catch (JRException e) {
    e.printStackTrace();
    }
    }
    }

  • 相关阅读:
    Template-网页模板:百科
    POJ 1743 Musical Theme(后缀数组)
    android ProgressBar 样式讲解
    opencv显示鼠标所在位置的rgb值
    JSU 2013 Summer Individual Ranking Contest
    spring mvc 中文乱码 post与get的方法解决
    iphone/ipad实现自定义的开关UISwitch(continuous,clipsToBounds,userInteractionEnabled属性)
    hdu 2093
    poj 1180 斜率优化dp
    太空飞行计划问题
  • 原文地址:https://www.cnblogs.com/rain-tl/p/4883743.html
Copyright © 2020-2023  润新知