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