This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes jasper reports with subreports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "jasper reports with subreports" Watch "jasper reports with subreports" New topic

jasper reports with subreports

subu ananthram
Ranch Hand

Joined: May 16, 2004
Posts: 102
Hi I want to create a subreport with in a report.
I am trying to create a jaspersubreport and I want to integrate hql into it.
I dont know how to do so... Can anyone help me
This is what I have tried to do

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Transaction;
import org.hibernate.Query;
import java.util.List;
import java.lang.ClassLoader;
import java.util.HashMap;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperExportManager;
import java.util.Iterator;
import java.util.ArrayList;

public class TestJasperSubReports {

public static void main(String[] args) {
Session session = null;
Transaction tx=null;

// This step will read hibernate.cfg.xml and prepare hibernate for
// use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
ArrayList tmpList=new ArrayList();
tx = session.beginTransaction();
HashMap params=new HashMap();
//Read query for sugbreport
String hql="from HogwartStudentHouseDetails";
List subReportList=session.createQuery(hql).list();
Iterator itr=subReportList.iterator();
HogwartStudentHouseDetails ht=(HogwartStudentHouseDetails);
//Jasper subreport prep
InputStream subStream= TestJasper.class.getResourceAsStream("/JasperSub1.jrxml");
JasperDesign subReportDesign=JRXmlLoader.load(subStream);
JasperReport subCompiled=JasperCompileManager.compileReport(subReportDesign);
System.out.println("subReportSize is"+subReportList.size());
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(subReportList);

JasperPrint printSubreport = JasperFillManager.fillReport(subCompiled, params, ds);
JasperExportManager.exportReportToHtmlFile(printSubreport, "hogwart.html");

//Read query for main report
String hibernateql="from HogwartStudentDetails";

List mainList=session.createQuery(hibernateql).list();

//Prepare main report
InputStream mainStream= TestJasper.class.getResourceAsStream("/jasperhibernate.jrxml");
JasperDesign mainDesign=JRXmlLoader.load(mainStream);
JasperReport mainCompiled=JasperCompileManager.compileReport(mainDesign);
JRBeanCollectionDataSource mainDS = new JRBeanCollectionDataSource(mainList);
JasperPrint printMainreport = JasperFillManager.fillReport(mainCompiled, params, mainDS);

JasperExportManager.exportReportToHtmlFile(printMainreport, "hogwartstudent.html");

System.out.println("in here");

}catch(Exception e){
System.out.println("inside catch");
// Actual contact insertion will happen at this step
System.out.println("Inside finally");



Both the hogwart.html and hogwartStudents.html are ok they print the righ tdata now how do I make it a subreport in Jasper
this is my xml



[added code tags]
[ March 16, 2006: Message edited by: Jeanne Boyarsky ]
Don't get me started about those stupid light bulbs.
subject: jasper reports with subreports
It's not a secret anymore!