• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

jasper reports with subreports

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

Code
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;

try{
// 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();
params.put("title","dd");
//Read query for sugbreport
String hql="from HogwartStudentHouseDetails";
List subReportList=session.createQuery(hql).list();
Iterator itr=subReportList.iterator();
while(itr.hasNext()){
HogwartStudentHouseDetails ht=(HogwartStudentHouseDetails)itr.next();
System.out.println("--"+ht.getStudentHouse());
}
//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");
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
System.out.println("Inside finally");
session.flush();
session.close();

}

}}


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

JasperSub1.jrxml


Thanks
subu

[added code tags]
[ March 16, 2006: Message edited by: Jeanne Boyarsky ]
 
See where your hand is? Not there. It's next to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic