
I want to display the report at the specific time from the data base in my JSP page

Here is the program and you need a xml file where your sql qurys would be there.
catgory.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="PDFReport" pageWidth="975">
<reportFont name="Arial_Normal" isDefault="true" fontName="Arial" size="15" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<reportFont name="Arial_Bold" isDefault="false" fontName="Arial" size="15" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<reportFont name="Arial_Italic" isDefault="false" fontName="Arial" size="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<parameter name="id" class="java.lang.Integer"/>
<parameter name="ReportTitle" class="java.lang.String"/>
<queryString><![CDATA[SELECT Stu_Id, Stu_Name, Stu_Class FROM stu_table_backup WHERE Stu_Id=$P{id}]]></queryString>
<field name="Stu_Id" class="java.lang.Integer"/>
<field name="Stu_Name" class="java.lang.String"/>
<field name="Stu_Class" class="java.lang.String"/>
<title>
<band height="50">
<textField>
<reportElement x="350" y="0" width="200" height="50" />
<textFieldExpression class="java.lang.String">$P{ReportTitle}</textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band>
</band>
</pageHeader>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement>
<font isUnderline="false" reportFont="Arial_Bold"/>
</textElement>
<text><![CDATA[Stu_Id]]></text>
</staticText>
<staticText>
<reportElement x="125" y="0" width="100" height="20"/>
<textElement>
<font isUnderline="false" reportFont="Arial_Bold"/>
</textElement>
<text><![CDATA[Stu_Name]]></text>
</staticText>
<staticText>
<reportElement x="250" y="0" width="150" height="20"/>
<textElement>
<font isUnderline="false" reportFont="Arial_Bold"/>
</textElement>
<text><![CDATA[Stu_Class]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{Stu_Id}]]></textFieldExpression>
</textField>
<textField pattern="0.00">
<reportElement x="125" y="0" width="100" height="20"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Stu_Name}]]></textFieldExpression>
</textField>
<textField pattern="0.00">
<reportElement x="250" y="0" width="150" height="20"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Stu_Class}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band>
</band>
</columnFooter>
<pageFooter>
<band height="15">
<staticText>
<reportElement x="0" y="0" width="40" height="15"/>
<textElement>
<font isUnderline="false" reportFont="Arial_Italic"/>
</textElement>
<text><![CDATA[Page #]]></text>
</staticText>
<textField>
<reportElement x="40" y="0" width="100" height="15"/>
<textElement>
<font isUnderline="false" reportFont="Arial_Italic"/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band>
</band>
</summary>
</jasperReport>
java program
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author chandan
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRXlsExporter;
public class Report {
public static void main(String args[]) {
JasperReport jasperReport;
JasperPrint jasperPrint;
Connection con = null;
Statement smt = null;
try {
HashMap jasperParameter = new HashMap();
Class.forName("com.mysql.jdbc.Driver");
String URL = "jdbc:mysql://localhost:3306/test";
con = DriverManager.getConnection(URL, "root", "root");
jasperParameter.put("id", new Integer(4));
jasperReport = JasperCompileManager.compileReport("C:/catalog.xml");
jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, con);
JasperPrintManager.printPage(jasperPrint, 0, true);
// JRXlsExporter exporter = new JRXlsExporter();
// exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
// exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "E:/simple_report.xls");
// exporter.exportReport();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Just try it.it will work
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.