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

jasper3

时间:2015-10-15 23:42:51      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

package jasper;

import java.io.ByteArrayInputStream;
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 org.omg.CORBA_2_3.portable.InputStream;

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.JasperRunManager;
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 {


byte[] bytes1=JasperRunManager.runReportToPdf(sourceFileName1, parameters,con);
byte[] bytes2=JasperRunManager.runReportToPdf(sourceFileName2, parameters,con);
byte[] bytes3=JasperRunManager.runReportToPdf(sourceFileName3, parameters,con);
byte[] total;
total=byteMerger(bytes1,bytes2);
byte[] result=byteMerger(bytes3,total);
System.out.println(bytes1.length);
System.out.println(bytes2.length);
System.out.println(bytes3.length);

System.out.println(total.length);

File reportFile = new File("f://demo.pdf");
OutputStream ouputStream = new FileOutputStream(reportFile);
ouputStream.write(result);
ouputStream.flush();
ouputStream.close();

} catch (JRException e) {
e.printStackTrace();
}
}
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2){
byte[] byte_3 = new byte[byte_1.length+byte_2.length];
System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
return byte_3;
}

}

jasper3

标签:

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

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