You can check this for step by step calling jasper report
http://sameh-nassar.blogspot.ie/2012/12/using-jasper-report-in-adf-application.html
One of the solutions for generating reports when you use JDeveloper is using Jasper Report.
Jasper report is some of libraries (.Jar files) and .xml or .jrxml file that represent your report.
One of the easy ways to write .xml file is using IReport program. IReport is a program that manage you to design your report graphically then save your report to xml or jrxml file. From JDeveloper after you add jasper reports libraries to your project you can read your report (.xml file) and print it as PDF file or Excel File or Jasper Viewer.
http://sameh-nassar.blogspot.ie/2012/12/using-jasper-report-in-adf-application.html
One of the solutions for generating reports when you use JDeveloper is using Jasper Report.
Jasper report is some of libraries (.Jar files) and .xml or .jrxml file that represent your report.
One of the easy ways to write .xml file is using IReport program. IReport is a program that manage you to design your report graphically then save your report to xml or jrxml file. From JDeveloper after you add jasper reports libraries to your project you can read your report (.xml file) and print it as PDF file or Excel File or Jasper Viewer.
Jasper Report Libraries is:
1-commons-digester-1.7.jar
2-itext-1.4.5.jar
3-jasperreports-3.0.0.jar
4-poi-2.5.1-final-20040804.jar
5- jasper-compiler-jdt-5.5.15.jar
2-itext-1.4.5.jar
3-jasperreports-3.0.0.jar
4-poi-2.5.1-final-20040804.jar
5- jasper-compiler-jdt-5.5.15.jar
You Can Download IReport From :
To configure your application to use Jasper Reports:
1- Add jasper report libraries to your project.
2- In web.xml add this
< resource-ref>
< res-ref-name> jdbc/OracleDBConnectionDS < /res-ref-name>
< res-type> javax.sql.DataSource < /res-type>
< res-auth> Container < /res-auth>
< /resource-ref>
3- From backingbean write this method:
----------- Imports ----------------
import java.io.*;
import java.util.*;
import java.sql.Connection;import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.InitialContext;import javax.naming.NamingException;
import net.sf.jasperreports.engine.*;
import java.util.*;
import java.sql.Connection;import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.InitialContext;import javax.naming.NamingException;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
----------------------------------------
public void printReport() throws FileNotFoundException, JRException, NamingException, SQLException, IOException {
InputStream input = new FileInputStream(new File("c:/yourJasperReport.xml"));
JasperDesign design = JRXmlLoader.load(input);
JasperReport report = JasperCompileManager.compileReport(design);
JasperReport report = JasperCompileManager.compileReport(design);
Map parameters = new HashMap();
// parameters.put("jasperParamenterName", "ParameterValue"); Used if you want to pass a parameter to a jasper report
InitialContext initialContext = new InitialContext();
DataSource ds = (DataSource)initialContext.lookup("java:comp/env/jdbc/OracleDBConnectionDS"); // get from your application module configuration
Connection conn = ds.getConnection();
JasperPrint print = JasperFillManager.fillReport(report, parameters, conn);
///// For printing report as PDF file ////////
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream(); JasperExportManager.exportReportToPdfStream(print,byteArrayOutputStream);
///// For printing report as PDF file ////////
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream(); JasperExportManager.exportReportToPdfStream(print,byteArrayOutputStream);
out.write(byteArrayOutputStream.toByteArray());
out.flush();
out.close();
FacesContext.getCurrentInstance().responseComplete();
//////// For printing report as excel file //////
OutputStream ouputStream = new FileOutputStream(new File("c:/yourReport.xls")); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); JRXlsExporter exporterXLS = new JRXlsExporter();
OutputStream ouputStream = new FileOutputStream(new File("c:/yourReport.xls")); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, print); exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);
exporterXLS.exportReport();
ouputStream.write(byteArrayOutputStream.toByteArray());
ouputStream.flush();
ouputStream.close();
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler c:/yourReport.xls");
///// for printing report as a jasper report viewer /////
JasperViewer.viewReport(print, true);
///// for printing report as a jasper report viewer /////
JasperViewer.viewReport(print, true);
}
For More Information About Using Jasper Report :