wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes how to generate dynamic reports in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "how to generate dynamic reports in java" Watch "how to generate dynamic reports in java" New topic
Author

how to generate dynamic reports in java

sshruti dere
Greenhorn

Joined: Sep 20, 2011
Posts: 3
How to generate dynamic reports using netbeans for a website?
I have display the data in my database in the form of piecharts and bar graphs?
M using postgres database and struts framework...
Please help...
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

You could create dynamic graphs with HTML5 Canvas using the data from your database.


OCA7
Gaurav Sainii
Greenhorn

Joined: May 18, 2009
Posts: 24
You can also try jasper java reporting API.
sshruti dere
Greenhorn

Joined: Sep 20, 2011
Posts: 3
Thank you so much...
Can you please explain me indetail... what exactly should i do...
Because I have downloaded plugin for ireports and jasperreports...
But I dont know exactly how to use it...
Please reply...
Mr sujeet khandelwal
Greenhorn

Joined: Dec 21, 2011
Posts: 13
Use this link it will be very helpful for you.. http://aspalliance.com/1140_Creating_Report_Using_JasperReports.all

Servlet code for jasperreports:


import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.export.*;

public class JasperReportServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
ServletOutputStream servletOutputStream = response.getOutputStream();
Connection conn = null;
JasperReport jasperReport;
JasperPrint jasperPrint;
JasperDesign jasperDesign;
try
{
// get a database connection
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection
("jdbc: oracle:thin:@192.168.10.85:1521: oracledb", "xyz","abc");

// create a map of parameters to pass to the report.
Map parameters = new HashMap();
parameters.put("Report_Title", "Salesman Details");

// load JasperDesign from XML and compile it into JasperReport
jasperDesign = JRXmlLoader.load("C:/jasperReports/demo.jrxml");
jasperReport = JasperCompileManager.compileReport(jasperDesign);

// fill JasperPrint using fillReport() method
jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,conn);

JasperExportManager.exportReportToPdfFile(jasperPrint,
"C:/jasperReports/demo.pdf");
response.setContentType("application/pdf");
//for creating report in excel format
JRXlsExporter exporterXls = new JRXlsExporter();
exporterXls.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporterXls.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
"C:/jasperReports/demo.xls");
exporterXls.exportReport();
JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);

servletOutputStream.flush();
servletOutputStream.close();
}
catch(SQLException sqle)
{
System.err.println(sqle.getMessage());
}
catch (ClassNotFoundException e)
{
System.err.println("No such class found!");
}
catch (JRException e)
{
// display stack trace in the browser
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
response.setContentType("text/plain");
response.getOutputStream().print(stringWriter.toString());
}
finally
{
//close the connection.
if(conn != null)
{
try { conn.close(); }
catch (Exception ignored) {}
}
}
}
}

Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

Here is a working example of jasper reports on java servlets.

http://www.onlinexamples.com/showfullexample.action?idexamples=28&title=Jasper%20Report%20Example
 
 
subject: how to generate dynamic reports in java