• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

i need help on java database arithemetic

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day experts, this code was aimed at performing calculation and inserting the total to database. however, it can only add the first and second amount hence

for example amount = first or existing amount in the database=300
rs.getInt(1) = second amount to be inputed =200
total =500.
Now when I want to input the third amount as per rs.getInt eg 400
the total amount will still remain 500 instead of 900 that is 300+200+900
My question is how do solve the problem so that the total column will be on the increase whenever new amount as per rs.getInt(1) is added
amount = first table column and data type is int hence getInt(1)
total = second column
student= third column
below is the code



 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please take the time to choose an appropriate forum for your posts. This forum is for questions on JSP. For more information, please click this link ⇒ CarefullyChooseOneForum.

This post has been moved to a more appropriate forum.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't "database arithmetic", this is just ordinary programming logic. You want to find the sum of rs.getInt(1) over all rows?


Edit: no, actually now that I look closer at your post, that isn't what you want. But I can't understand what you do want. You said

Now when I want to input the third amount as per rs.getInt eg 400


I don't understand. You want to "input" an amount? From where?
 
muntago Richard
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I have done what you said and i have done some modifications, but now the student score is added from the input form with respect to a particular student id,
the total will be updating anything it likes. assuming in the first place at test1.jsp i added
student id=2011
student name=mutago
student score=80
function = addition and click submit, the value will be submitted.
I now go back to test1.jsp and add again

student id=2011
student name=mutago
student score=70
function=addition.
when i click submit, my total is supposed to be 150 but rather it will update any value it likes

If try the third time assuming the score now is 50 , my total is supposed to be 200 ie 80+70+50 but it will keep on displaying any thing it like below is the full code thanks


 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are probably more issues with your code, but on line 40 of test2.jsp you're trying to insert a new record for student even if it already exists in the database. It seems syntactically incorrect to me, but maybe your database can accept it. If it is the case, you then have more than one record per student here, which would allow for same scenarios corresponding to the symptoms you've described above.

You should use UPDATE instead of INSERT there. Moreover, you should define primary key on your STUDENT table so that inserting a duplicate record would fail immediately (this would provide you more clues as to where the problem actually is).

There are other potential issues.

I don't do JSP, but seasoned JSP programmers would probably advice you not to include database code in JSP pages.

The STUDENT table has fields named SCORE and TOTAL. Is the requirement really to keep total of the score and the last score assigned to the student? Should not all individual scores be recorded for every student, not just the last one?
 
muntago Richard
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have tried it but it doesn't work. thanks
 
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic