wood burning stoves 2.0*
The moose likes JDBC and the fly likes How i will display Total Value for all the page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How i will display Total Value for all the page" Watch "How i will display Total Value for all the page" New topic
Author

How i will display Total Value for all the page

sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear Sir,
In my develpment i am getting stuck for a senario.Kindly please help me for it.

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)




Thanks a lot in Advance.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150


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

Joined: Jun 23, 2008
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+.....


Thanks a lot in Advance.

Regards
Sumanta
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
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

Joined: Jun 23, 2008
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.

Thank you for your suppport.Hope i waiting for your response.

Regards
Sumanta
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
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
%>

Thanks a lot in Advance.
Regards
Sumanta
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Hi ALL,
please any body guide me to rectify my code.

Thanks and Regards
Sumanta
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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

Joined: Feb 22, 2007
Posts: 285
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

Joined: Jun 23, 2008
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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

Joined: Oct 08, 2006
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

Joined: Oct 13, 2005
Posts: 38087
    
  22
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."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How i will display Total Value for all the page
 
Similar Threads
won't create tables with jaws.xml
Session value is not reflection properly for view the page in next time in post login
(How do i do paging in JSP ????? HELP ME >URGENT
urgent urgent .....How do i do paging in JSP ?????
Pagination In struts with oracle database