• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • salvin francis
  • Piet Souris

jasper reports with subreports

Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 java.io.InputStream;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
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)itr.next();
//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 ]
I love a woman who dresses in stainless steel ... and carries tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!