# How i will display Total Value for all the page

sumanta panda
Ranch Hand
Posts: 224
Dear Sir,

Everytime we give the request we get the response of 8 records and
its corresponding value.
Then next button will display more and more records if it is availbale in data base.

CMP is a column in the this record.

i want to calculate all the CMP value which displyed in total pages
and its value will populate in Total =<%TotalCMP%>

Let say in the first page i get 8 records then .Then CMP value in the
page1total=200+100+20+1+1+1+1+1

page2total=page1total+(8 filed data of page 2 in cmp)

if page is the final page of record
then page3finalcmptotal=page1total+page2total+(8 filed data of page 2 in cmp)

Total will papulate Total CMP =<%TotalCMP%> (PAGE NO ARE DYMANIC)

Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34641
363
Sumanta,
You would do two database queries. One to get the data for the page your are displaying. And another to get the sum for all the matching records.

sumanta panda
Ranch Hand
Posts: 224
Dear Sir,
My doubt is sum value is comming in out.println("Sum value"+sum);
Sum value200
Sum value200
Sum value200
Sum value200
Sum value200
Sum value200
Sum value200
Sum value200

Total value should display 1600.But could you please suggest me sir why i did nt i get Total value 1600.Please rectify my code.
<%
for(int iCount=0;iCount < iNoOfRec;iCount++ )
{

int sum=Integer.parseInt((String)inVec.elementAt(3));
total=total+sum;
out.println("Sum value"+sum);
out.println("total value"+total);

}
%>

Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34641
363

Currently the code only adds the fourth element repeatedly. I assume this is a typo and you mean to use "i" as the index.

sumanta panda
Ranch Hand
Posts: 224
Dear Sir,
I am using Paging Concept.Everytime when i give the request i will get the data

Every page 8 records are comming then next button click next record will displayed.

Sir Now i am getting Total CMP value for the every page Which is displayed the
correct value.But i have to add all the page CMP value and dispalyed Total CMP.

Total Cmp=Pageing 1 data CMP total+Pageing 2 data CMP total+Pageing 3 data CMP total(Until the page is not completed).

Dear Sir i am begineer of j2ee programmer,Could you please suggest me how i will
approch to store old page data and dispyed total data once the page record is completed in one page(Paging concept).

int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));
cmp=cmp+cmp_temp;

out.println("CMP VALUE"+ cmp);

}

I want like Total Cmp=page1 cmp value+page2 cmp value+page3 cmp value+.....

Regards
Sumanta

raj malhotra
Ranch Hand
Posts: 288
Total value should display 1600.But could you please suggest me sir why i did nt i get Total value 1600.Please rectify my code.

Hi Sumanta
You must have declared the total(By total i mean whichever variable you have chosen to store the first to current page sum) variable in the scriptlet.so it becomes a local variable to service method.so everytime the request goes to servlet thread and service method is called ,total will be reinitialize.In case you want to make it a static variable then you should declare it in declaration rather than scriptlet.

Please correct me if i am wrong.

I have one doubt .Should it be static variable or instance variable

Thanks
Raj

[ December 26, 2008: Message edited by: raj malhotra ]
[ December 26, 2008: Message edited by: raj malhotra ]

sumanta panda
Ranch Hand
Posts: 224
Dear Raj Sir,
Its a static variable.
I want like Total Cmp=page1 cmp value+page2 cmp value+page3 cmp value+.....

(I am using paging concept)Please guide me for the needful.I am beginner in j2ee concept.

Regards
Sumanta

sumanta panda
Ranch Hand
Posts: 224
Dear Raj Sir/All,
Please rectify this above code else give me some alternative soln for this issue.
for(int iCount=0;iCount < iNoOfRec;iCount++ )
{
int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));
cmp=cmp+cmp_temp;//Cmp value is comming correctly in every page record
session.putValue("variable","cmp");
}

<%
String temp;int TotalCMP;
String temp=session.getValue("varible");
TotalCMP=TotalCMP+Integer.parseInt((String)temp);//Not geeting the all pages CMP total value
%>

Regards
Sumanta

sumanta panda
Ranch Hand
Posts: 224
Hi ALL,
please any body guide me to rectify my code.

Thanks and Regards
Sumanta

Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34641
363
Originally posted by sumanta panda:
int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));

I didn't see where you replied to my comment about hard coding 3 instead of i. Can you explain why this part is correct?

raj malhotra
Ranch Hand
Posts: 288
HI Sumanta
Jeanne is right you have not answered his question.
I think you have not posted your original code.Because there seems to be number of mistakes in your code.
for example-

Here you are setting String variable 'variable' whose content is 'cmp' and not any number.

sumanta panda
Ranch Hand
Posts: 224
It means inVec i am getting all of indivisul data.and it will in loop unless the count is not completed.
That is why Raj Sir/All i have informed you i am begineer in j2ee and i am facing bit difficulties in coding.
As i am develping real live project so i am facing in syntax.But honestly speaking if i will achieve some mile
stone of my project then this because the technical staff of java ranch people who helped us a lot.Now i am reading
Head first servlet/jsp but i have to finish it because of project deadline.Could you please rectify my code
or else give me some suggestion from your side how i will approach it.

for(int iCount=0;iCount < iNoOfRec;iCount++ )
{

inVec= (Vector) vData.elementAt(iCount);
<INPUT TYPE="text" NAME="Symbol<%=iCount%>" DISABLED VALUE="<%=(String) inVec.elementAt(0)%>">
<INPUT TYPE="text" NAME="ISIN<%=iCount%>" DISABLED VALUE="<%=(String) inVec.elementAt(1)%>"></TD>
<INPUT TYPE="text" NAME="FB<%=iCount%>" DISABLED VALUE="<%=(String) inVec.elementAt(2)%>"></TD>

for(int iCount=0;iCount < iNoOfRec;iCount++ )
{
int cmp_temp=Integer.parseInt((String)inVec.elementAt(3));//Here sir all values of CMP is comming in pages
cmp=cmp+cmp_temp;//Cmp value is comming correctly in every page record
session.putValue("variable","cmp");
}

<%
String temp;int TotalCMP;
String temp=session.getValue("varible");
TotalCMP=TotalCMP+Integer.parseInt((String)temp);//Not geeting the all pages CMP total value(Total CMP=cmp page 1+cmp page2 +.....
%>

Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34641
363
Originally posted by sumanta panda:
i am facing bit difficulties in coding.
As i am develping real live project so i am facing in syntax.

In that case, let's start with that. What syntax error are you getting when you run the JSP? Post the error and the line(s) of code containing that error and someone can help you with that.

Nobody is going to run your code and fix all the errors. That's not the job of JavaRanch. What we will do is help you with specific errors.

Bauke Scholtz
Ranch Hand
Posts: 2458
Originally posted by raj malhotra:
Jeanne is right you have not answered his question.

A small detail: Jeanne is in this part of the world (the west) a maiden name.

Campbell Ritchie
Sheriff
Posts: 49361
62
Originally posted by Bauke Scholtz:

A small detail: Jeanne is in this part of the world (the west) a maiden name.

You mean a woman's name. Many people call Jeanne "Sir."