Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to store a value in a variable for future use after performing sum function on a column?

 
Yuta Lolap
Ranch Hand
Posts: 86
Eclipse IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am trying to use the sum function here to calculate the total price of items that has been stored in Itemprice Column of type Number(10).

The query is as follows :

String query="select sum(itemprice) as 'totalbill' from purchases where customer_id ="+custidforbill;


So when we usually execute this in cmd we get the output as a column with a name as total bill and the amount written below it. Can i use this column name and then say rs.getInt("totalbill") and store it in another variable for future use?




 
Waldemar Macijewski
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I don't know if this might solve your problem, but there is a feature called Serialization in Java. Serialization is, basically, a feature which allows you to save object's state into persistent storage area such as memory, or a file. So you could for example, save that variable's value into a file using serialization, and later retrieve whats necessary from that file.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Waldemar Macijewski wrote:Hi.

I don't know if this might solve your problem, but there is a feature called Serialization in Java. Serialization is, basically, a feature which allows you to save object's state into persistent storage area such as memory, or a file. So you could for example, save that variable's value into a file using serialization, and later retrieve whats necessary from that file.

Be careful about storing values in different places as your stored value will become obsolete as soon as the database is updated with another purchase by a given customer.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, but as as chris pointed out, keep a very check on the value of the data, i would only hold onto this data for a really short time before wanting to check again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic