zoukankan      html  css  js  c++  java
  • 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();
    }
    }
    }

  • 相关阅读:
    传统目标检测主要结构原理讲解(去除了冗余的知识)
    redis部署,linux下秒级定时监控服务脚本
    第一个脚本部署案例,比较简单,还有redis的部署脚本没有写完
    fabric-sdk-go client开发
    fabric-sdk-go ca开发
    fabric-sdk-go config详解
    pkg/client/msp msp包
    pkg/client/resmgmt resmgmt包
    pkg/client/ledger ledger包
    pkg/client/event event包
  • 原文地址:https://www.cnblogs.com/rain-tl/p/4883743.html
Copyright © 2011-2022 走看看