• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to generate dynamic reports in java

 
sshruti dere
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
Java Tomcat Server Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create dynamic graphs with HTML5 Canvas using the data from your database.
 
Gaurav Sainii
Greenhorn
Posts: 24
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also try jasper java reporting API.
 
sshruti dere
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
Java Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a working example of jasper reports on java servlets.

http://www.onlinexamples.com/showfullexample.action?idexamples=28&title=Jasper%20Report%20Example
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic