3.7.6: iReport instruction(when software open then do it) or To Set the ORACLE
Driver to Connect the ORACLE database:
At first jar (ojdbc14.jar) put on desktop from anywhere then it will be call
from iReport software –> Tools –> options –> class path then click add jar button.
Sample (Help - Samples) run using by HSQLDB
1.7.0 version :
Report code apply in java class
public void showReport(String accID) throws JRException, ServletException, IOException{
Connection connection = null;
HttpServletResponse response=ServletActionContext.getResponse();
//HttpServletRequest request=ServletActionContext.getRequest();
String filename ="report2Appointment.jasper";//request.getParameter(“filename�);
String outputFileName ="report2Appointment";
//String reportType = request.getParameter("reportType");
String reportType ="pdf";
//String accID=request.getParameter("accNo");
Map parameters = new HashMap();
//All the parameter you want to pass to report write below way..
parameters.put("p_appoint_no", accID);
//parameters.put(“userFullName�, userFullName);
//DatabaseConnection db=new DatabaseConnection();
connection = dbc.connectDB();
ServletContext context = ServletActionContext.getServletContext();
String path = context.getRealPath("/");//.getContextPath();
JasperPrint jasperPrint = JasperFillManager.fillReport(path +"/Jasper"+ "/" +filename,parameters, connection);
System.out.println("Report Created…");
OutputStream ouputStream = response.getOutputStream();
JRExporter exporter = null;
if ("pdf".equalsIgnoreCase(reportType)) {
response.setContentType("application/pdf");
// If you want show the report in the browser then write “inline�
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
// If you want show the report out of the browser as a .pdf format then write “attachment�
//response.setHeader(“Content-disposition�, “attachment;filename=�+outputFileName+�.�+reportType);
exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("rtf".equalsIgnoreCase(reportType)) {
response.setContentType("application/rtf");
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
exporter = new JRRtfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("html".equalsIgnoreCase(reportType)) {
exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("xls".equalsIgnoreCase(reportType)) {
response.setContentType("application/xls");
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("csv".equalsIgnoreCase(reportType)) {
response.setContentType("application/xls");
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
exporter = new JRCsvExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
try {
ouputStream.close();
} catch (IOException ex) {
}
}
}
}
**/ View report from project report jar will be store in the project library ( WEB-INF/lib/iReport.jar )
1.7.0 version :
Report code apply in java class
public void showReport(String accID) throws JRException, ServletException, IOException{
Connection connection = null;
HttpServletResponse response=ServletActionContext.getResponse();
//HttpServletRequest request=ServletActionContext.getRequest();
String filename ="report2Appointment.jasper";//request.getParameter(“filename�);
String outputFileName ="report2Appointment";
//String reportType = request.getParameter("reportType");
String reportType ="pdf";
//String accID=request.getParameter("accNo");
Map parameters = new HashMap();
//All the parameter you want to pass to report write below way..
parameters.put("p_appoint_no", accID);
//parameters.put(“userFullName�, userFullName);
//DatabaseConnection db=new DatabaseConnection();
connection = dbc.connectDB();
ServletContext context = ServletActionContext.getServletContext();
String path = context.getRealPath("/");//.getContextPath();
JasperPrint jasperPrint = JasperFillManager.fillReport(path +"/Jasper"+ "/" +filename,parameters, connection);
System.out.println("Report Created…");
OutputStream ouputStream = response.getOutputStream();
JRExporter exporter = null;
if ("pdf".equalsIgnoreCase(reportType)) {
response.setContentType("application/pdf");
// If you want show the report in the browser then write “inline�
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
// If you want show the report out of the browser as a .pdf format then write “attachment�
//response.setHeader(“Content-disposition�, “attachment;filename=�+outputFileName+�.�+reportType);
exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("rtf".equalsIgnoreCase(reportType)) {
response.setContentType("application/rtf");
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
exporter = new JRRtfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("html".equalsIgnoreCase(reportType)) {
exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("xls".equalsIgnoreCase(reportType)) {
response.setContentType("application/xls");
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
} else if ("csv".equalsIgnoreCase(reportType)) {
response.setContentType("application/xls");
response.setHeader("Content-disposition", "inline;filename="+outputFileName+"."+reportType);
exporter = new JRCsvExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
}
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
try {
ouputStream.close();
} catch (IOException ex) {
}
}
}
}
**/ View report from project report jar will be store in the project library ( WEB-INF/lib/iReport.jar )
No comments:
Post a Comment