Solved

About the jasper report

Posted on 2009-05-18
3
211 Views
Last Modified: 2012-05-07
  JRXmlDataSource xmlDataSource = new JRXmlDataSource(new File("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperXml/reports/userxml.xml"),"/userData/M55_USERS_NEW");

this line is not taken by my program

i
package net.ensode.jasperbook.struts;

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.InputStream;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.HashMap;

import javax.servlet.ServletOutputStream;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JasperCompileManager;

import net.sf.jasperreports.engine.JasperRunManager;
 

import net.sf.jasperreports.engine.data.JRXmlDataSource;

import org.apache.struts.action.Action;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

 

public class GenerateReportAction extends Action

{

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception

{

     Connection connection=null;

     Statement statement=null;

     ResultSet resultSet=null;

//     ServletContext application=servlet.getServletContext();

//     DataSource datasource = (DataSource) application.getAttribute(Globals.DATA_SOURCE_KEY);

//     ConnectionPool.dsource=datasource;

     ServletOutputStream servletOutputStream =response.getOutputStream();

     response.setContentType("application/pdf"); 
 

     try{

         

        String query="select * from M55_USERS_NEW";

//         connection=ConnectionPool.openConnection();

         System.out.println("After load Driver========================");

//         statement = connection.createStatement();

//         resultSet = statement.executeQuery(query);

 //        JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(resultSet);

         System.out.println("Compiling report...");

         JasperCompileManager.compileReportToFile("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperXml/reports/RemoteReport.jrxml");

         System.out.println("Compilation Succesfully----------------------->");

         System.out.println("Filling report...");

         InputStream reportStream=new FileInputStream("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperCompleteApplication/reports/RemoteReport.jasper");

         System.out.println("ReportStream---------->>>>>>>>>>>>>>>>"+reportStream.toString());

         System.out.println("Done!");
 

 //       InputStream xmlFile=new FileInputStream("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperXml/reports/userxml.xml");

//         JRXmlDataSource xmlDataSource=new JRXmlDataSource(xmlFile,"/userData/M55_USERS_NEW");

       

       JRXmlDataSource xmlDataSource = new JRXmlDataSource(new File("C:/Documents and Settings/ashish/My Documents/NetBeansProjects/StrutsJasperXml/reports/userxml.xml"),"/userData/M55_USERS_NEW");

            System.out.println("After XMl  xmlDataSource read------->");

         JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap(),xmlDataSource);

  

        }catch(Exception e){

            e.printStackTrace();

        }

     finally{

//        resultSet.close();

 //       statement.close();

//        ConnectionPool.closeConnection(connection);

        servletOutputStream.flush();

        servletOutputStream.close();

     }

     return mapping.getInputForward();

    }

}

Open in new window

0
Comment
Question by:achitaley
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 24410526
what do you need it for?
0
 

Author Comment

by:achitaley
ID: 24570690
i got the solution
0
 

Author Closing Comment

by:achitaley
ID: 31582535
not a proper solution
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 68
backtracking recursion  code 19 53
Error trying to install RTMT Win7 5 40
netstat -ano | find "8000" and taskkill /f /pid 2984 3 32
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now