can anyone help me to send the code for Jasper Reporting in
java?plz

Answers were Sorted based on User's Feedback



can anyone help me to send the code for Jasper Reporting in java?plz..

Answer / shabbir ahmed

For Example use this code..I hope it will help u.
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import org.apache.commons.digester.Digester;
import net.sf.jasperreports.engine.design.*;
import net.sf.jasperreports.engine.*;
import java.util.*;

public class Report
{
public void viewReport()
{


String reportSource
= "HelloReportWorld.jrxml";
String reportDest
= "HelloReportWorld.html";
String name=null;
System.out.println("Hello World!");
Map<String, String> params = new
HashMap<String, String>();
params.put("reportTitle", "Shabbir
Ahmed");
params.put("author", "shabbir");
params.put("startDate", (new
java.util.Date()).toString());

System.out.println("here1111111");
try
{
System.out.println
("here222222222");

JasperDesign jasperDesign =
JasperManager.loadXmlDesign
("D:/Tomcat/bin/HelloReportWorld.jrxml");
JasperReport jasperReport
=JasperCompileManager.compileReport(jasperDesign);

JasperPrint jasperPrint
=JasperFillManager.fillReport(jasperReport, params, new
JREmptyDataSource());


JasperExportManager.exportReportToHtmlFile
(jasperPrint, reportDest);

JasperViewer.viewReport
(jasperPrint);


}

catch (JRException ex)
{
System.out.println
("here6666666666666");
ex.printStackTrace();
}
catch(Exception e)
{
System.out.println
(e.getMessage());
}
}
}
////////This simple example shows how to pass parameters to
jrxml.as it is below.



<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dt
d">

<jasperReport name="HelloReportWorld">
<parameter name="reportTitle"
class="java.lang.String"/>
<parameter name="author" class="java.lang.String"/>
<parameter name="startDate" class="java.lang.String"/>
<title>
<band height="60">
<textField>
<reportElement x="0" y="10" width="500"
height="40"/>
<textElement textAlignment="Center">
<font size="24"/>
</textElement>
<textFieldExpression
class="java.lang.String">
<![CDATA[$P{reportTitle}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="500"
height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression
class="java.lang.String">
<![CDATA["Run by: " + $P{author}
+ " on " + $P{startDate}]]>
</textFieldExpression>
</textField>
</band>
</title>

<detail>
<band height="200">
<staticText>
<reportElement x="0" y="0" width="500"
height="20"/>
<text><![CDATA[Hello shabbir Report World!]]
></text>
</staticText>
</band>
</detail>
</jasperReport>


////All the best

Is This Answer Correct ?    7 Yes 1 No

can anyone help me to send the code for Jasper Reporting in java?plz..

Answer / ram

//this code is very easy any one can understand easily
//1. these are the packages which we need to import
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JRDesignQuery;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;

//2. this is the java code for developing reports

try{
Connection con=(Connection)
Connectivity.makeconnection();// Database Connection

File path=new File("Report/");
JasperDesign jasperDesign =
JRXmlLoader.load(path.getAbsolutePath()+"\\allbooksreport.jrxml");//here
allbooksreport is my jrxml file name ...//xml file

Map parameters = new HashMap();
parameters.put("DataSource" ,con);
JRDesignQuery query =new JRDesignQuery();
query.setText("select * from add_book");
jasperDesign.setQuery(query);
JasperReport jasperReport =
JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint =
JasperFillManager.fillReport(jasperReport,parameters,con);
JasperViewer vwrpt = new
JasperViewer(jasperPrint,false);
vwrpt.show(); //...//view the report
vwrpt.setTitle("All Books Report");
} catch(Exception e) {
e.getMessage();
}

Is This Answer Correct ?    1 Yes 0 No

can anyone help me to send the code for Jasper Reporting in java?plz..

Answer / shabbir ahmed

Hi am jasper report expert...Contact me for assistance

Is This Answer Correct ?    3 Yes 7 No

Post New Answer

More Struts Interview Questions

Can we write Structs application without using Action Class directly or indirectly(extends Action class)

5 Answers  


Which parser is used in Struts to parse the Structconfig.xml file.

21 Answers   iFlex,


What is includeaction?

0 Answers  


Can we have multiple struts config files in a single web app?

0 Answers  


where you will implement the tiles in struts?

2 Answers   Wipro,






what is project architecture?give brief explanation about project architecture?

3 Answers   CTS, Etisalat, IBM, Infinite Computer Solutions, Mphasis,


How to use forward action to restrict a strut application to mvc?

0 Answers  


When should be opt for struts framework?

0 Answers  


what is purpose cvs and vss in eclipse?

2 Answers  


What is the significance of logic tags in Struts?

0 Answers  


project architechture in java

3 Answers   AC, IBM, INDUS, Satyam,


What is the use of lookupdispatchaction?

0 Answers  


Categories