• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

total number

 
D Wynn
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question...I have a java servlet that reads a database and totals up a field off of the database and produces a total dollar amount here is the code...


And this works but if the field contains the same payable amount (example 150.00 is the payable amount for two fields) the amounts are not added together. Am I missing something?
[ October 03, 2005: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First I used the CODE tags and added indention to make it more readable.

For the inner most if statement there was no curly braces since I assume it was a one line after, but that makes code very unreadable and therefore easy to have problems not knowing which lines of code would run, which probably is leading to your actual problem.

So now, there is a curly brace missing based on probably putting in the curly braces in the wrong place, since it is unreadable to really know.

So please fix where the curly braces should go and you should always use curly braces even with a single line if statement.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Just a little rewrite.

Mark
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a servlet question, I'm moving it to Java in General (beginner)

Dave
 
Kenneth Albertson
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by D Wynn:
... if the field contains the same payable amount (example 150.00 is the payable amount for two fields) the amounts are not added together
Are you sure that your recordset actually contains duplicate copies of these values? Depending on your query, which you have not shown us, it might only return single instances for duplicate lines. Put some print statements in your loop to confirm that the recordset contents are what you expect.

Also, is there a reason for retrieving all the records, and then adding them up? A better approach would be to do the totalling in the database query.
 
D Wynn
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was only bringing back one copy of the value so I did a sum of the column in my query and it works!! Thanks for your help. I still wonder why my query wouldn't bring back both copies of the duplicate value??
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic