aspose file tools*
The moose likes JDBC and the fly likes how to store a value in a variable for future use after performing sum function on a column? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to store a value in a variable for future use after performing sum function on a column? " Watch "how to store a value in a variable for future use after performing sum function on a column? " New topic
Author

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

Yuta Lolap
Ranch Hand

Joined: Jun 03, 2012
Posts: 83

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

Joined: Jun 22, 2012
Posts: 32
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

Joined: Mar 01, 2009
Posts: 1774
    
  14

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.


No more Blub for me, thank you, Vicar.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

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.
 
wood burning stoves
 
subject: how to store a value in a variable for future use after performing sum function on a column?