Jump to content
We've recently updated our Privacy Statement, available here ×

Binding master/child report to database


ktrinad

Recommended Posts

By: adcworks - adcworkssf

Binding master/child report to database

2004-11-02 06:06

Hi All,

 

I am just getting started with JR and would like to pick your brains on my requirements. I have installed JasperAssistant also within Eclipse.

 

My system is an ordering system. The output of this system is an Order and 1 Order has some once-only details like Order Number and Customer Name, but also 1..N Order Line Items. The way this is stored in the database is fairly conventional, i.e 2 tables with a foreign key in line items to orders.

 

ORDERS

======

id | customer_name

 

LINE_ITEMS

==========

id | order_id

 

I need to generate a PDF version of this order roughly following this layout;

_______________

|id

|customer name

|______________

|

|line item 1

|line item 2

|line item 3

|line item 4

----------------

| footer |

----------------

 

From the documentation I have found, it would appear that data can be bound to my report template in many ways for data sources. The one I thought I would need which would be a connection to the database, does not appear to be right, because if I simply pointing my template at the ORDERS and LINE_ITEMS table, how would I join the 2 tables, i.e specify a WHERE clause. It also requires 2 queries to get my master detail and then line item detail. I am guessing a sub-report for the line items, but even then I need to specify to only retrieve line items for a particular master Order.

 

I am looking for some guidance on how I should be thinking about mapping a template to my database tables for this situation. I am finding it a little tough with the current documentation and even samples too, since the data source sample does not seem to illustrate this master/sub-data type scenario.

 

Your comments most welcome. Best wishes, AC.

 

 

 

By: Craig O'Shannessy - shanness

RE: Binding master/child report to database

2004-11-03 14:26

Hi AC,

 

The standard way to do this in Jasper is to have the Order has a "parameter", and the lineitems as the "datasource".

 

As a general rule, if there is only ONE for the whole report (such as an order, or address, or customer, or date etc), then it's a parameter. If there are multiple and you want jasper to iterate through them in the "details band", then it's a datasource (JavaBeansCollection, Resultset etc).

 

Hope this helps.

 

Craig.

 

P.S. Thanks for mentioning JasperAssistant, I had never heard of it. Unfortunately, I run Idea (IntelliJ), so I can't really use it :( You might also want to look at iReport.

 

http://ireport.sourceforge.net/

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...