码迷,mamicode.com
首页 > Web开发 > 详细

jasper2

时间:2015-10-15 22:00:52      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

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

jasper2

标签:

原文地址:http://www.cnblogs.com/rain-tl/p/4883743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!