Generating annual report and list the data into JTable

Hi, I am stuck with my project. I know that my logic is wrong, but I couldn't figure out the solution. Please help me.

I hava a database, one of the table is the booking information.

I need to generate a report which shows the number of booking for each companies for each month.

I have three data in my database, two different companies(XX and YY), with three different months(Jan, Feb, Jul).

The problem that I encountered is that the data shown is inaccurate. It showed 6 rows of data, and the number of booking is incorrect.

It showed :

Company Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

XX100000000000

XX110000000000

YY110000100000

How can I loop for different companies and add the number of booking each time and get the right output as follows?

Company Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

XX110000000000

YY000000100000

This is my partial code:

ArrayList stringList = dao.retrieveAllBooking();

for (int i = 0; i < stringList.size(); i++) {

ab = (AllBooking) stringList.get(i);

d = ab.getDATE_OF_USE_TO();

StringTokenizer ss = new StringTokenizer((String) d, "/");

String day = ss.nextToken();

String month = ss.nextToken();

String year = ss.nextToken();

Org = o.getORG_ID();

if(month.equals("JAN")){

JanDR++;

}

if(month.equals("FEB")){

FebDR++;

}

if(month.equals("MAR")){

MarDR++;

}

if(month.equals("APR")){

//Apr = ab.getNO_OF_REQ();

AprDR++;

}

if(month.equals("MAY")){

//MayDR = ab.getNO_OF_REQ();

MayDR++;

}

if(month.equals("JUN")){

//Jun = ab.getNO_OF_REQ();

JunDR++;

}

if(month.equals("JUL")){

JulDR++;

}

if(month.equals("AUG")){

AugDR++;

}

if(month.equals("SEP")){

SepDR++;

}

if(month.equals("OCT")){

OctDR++;

}

if(month.equals("NOV")){

NovDR++;

}

if(month.equals("DEC")){

DecDR++;

}

Object[] data={Org,JanDR, FebDR, MarDR, AprDR, MayDR, JunDR, JulDR, AugDR, SepDR, OctDR, NovDR, DecDR, JanSR, FebSR, MarSR, AprSR, MaySR, JunSR, JulSR, AugSR, SepSR, OctSR, NovSR, DecSR};

tableModel.addRow(data); //add the data to the table.

I'll appreciate for your help. Thanks.

[2400 byte] By [a1v1n4a] at [2007-11-27 11:06:29]
# 1

Off hand, it appears perhaps under certain circumstances you need to insert a new record, whereas under other circumstances you need to update (that is to say modify) the record by retrieving it, changing it, then updating it. If you pepper your code with System.out.println() statements, you can see where your problems occur in the code.

I say you may have inserted a record instead of updated due to your statement here. Looks like XX should have been one record rather than two.

Got:

XX 1 0 0 0 0 0 0 0 0 0 0 0

XX 1 1 0 0 0 0 0 0 0 0 0 0

YY 1 1 0 0 0 0 1 0 0 0 0 0

Expected:

XX 1 1 0 0 0 0 0 0 0 0 0 0

YY 0 0 0 0 0 0 1 0 0 0 0 0

George123a at 2007-7-29 13:15:44 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks for your reply.

Yes. I insert a new record when I add a new booking with XX and YY included. Hence it has more than one recordfor XX with different booking information.

Now I am supposed to summarise the monthy usage of each company (XX, YY).

In my example, there are a total of three records. However, when I print all the booking information, it actually printed six times, with the month increased, in irrelevant month and duplicated companies.

How can I summarise the month usage with the company name included in the table?

I appreciate for your time.

Message was edited by:

a1v1n4

a1v1n4a at 2007-7-29 13:15:44 > top of Java-index,Java Essentials,Java Programming...
# 3

> duplicated companies

If you use addRow() method, rows on the table would increase, increase and increase. Use setDataVector() method instead and update the table wholly. It should be needless to say that before calling the setDataVector() method, you must update table model data correctly.

hiwaa at 2007-7-29 13:15:44 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi. Thanks. I will try..

a1v1n4a at 2007-7-29 13:15:44 > top of Java-index,Java Essentials,Java Programming...