Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

About the jasper report

Posted on 2009-05-18
3
Medium Priority
?
351 Views
Last Modified: 2012-06-21
I m getting an exception in that line  when i connect the xml as a datasource
   JRXmlDataSource xmlDataSource = new JRXmlDataSource("xmlFile","/userData/M55_USERS_NEW");
And this two exception are also come with that program
1)net.sf.jasperreports.engine.JRException: Failed to parse the xml document
2) C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.18\bin\xmlFile (The system cannot find the file specified)

and how can i write the query also in java code to select data from xml file
please tell me some solution
package net.ensode.jasperbook.struts;
import java.io.BufferedInputStream;
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.JRResultSetDataSource;
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("xmlFile","/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();
    }
}
 
and at the end i  am giving the xml code  also..
 
 
<userData>
<M55_USERS_NEW>
    <USER_ID >1</USER_ID >
    <USER_LOGIN >ashish</USER_LOGIN >
    <USER_FULL_NAME>ashish limje</USER_FULL_NAME >
    <USER_PASSWORD>ashish</USER_PASSWORD>
    <USER_ACTIVE_STATUS>1</USER_ACTIVE_STATUS>
</M55_USERS_NEW>
</userData>

Open in new window

0
Comment
Question by:Adwait Chitaley
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 24410219
> JRXmlDataSource xmlDataSource = new JRXmlDataSource("xmlFile","/userData/M55_USERS_NEW");

try:

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

0
 

Author Comment

by:Adwait Chitaley
ID: 24570742
i tried this but not work
0
 

Author Closing Comment

by:Adwait Chitaley
ID: 31582517
not a proper solution
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

782 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