Mathematical Operations from RowSet data.

I'm sure there's got to be a way to take integer data from two columns and perform a mathematical operation between the two of them, right?

My intention is to create output, per row, based on the two colums in a table identified as 'Quantity' and 'Unit Price.'

Example: (Here's my code that doesn't work, since I'm still a beginner and can't figure out the right syntax. Don't laugh.)

ext_price_output.setObject((Integer)(getValue("#{currentRow.unit_price}") * getValue("#{currentRow.qty}")));

Is there any hope for me?

[568 byte] By [Morguen] at [2007-11-25 19:39:20]
# 1

Hi,

One of the approaches to do it is construct your query something like this:

SELECT QUANTITY, UNIT_PRICE, QUANTITY * UNIT_PRICE AS AMOUNT FROM <TABLE NAME>

The other approach would be to assign the records from the rowsets to an multi dimensional array. By iterating through the array calculate the product of quantity and unit price and then store it. This can be assigned to the outputText component.

Hope this helps

Cheers

Giri :-)

Creator Team

mayagiri at 2007-7-4 12:38:51 > top of Java-index,Development Tools,Java Tools...
# 2
It works perfectly. I wish I had thought about calculating the values on the database side instead of stressing over ways to make the application do it.Thanks again for pointing me in the right direction.
Morguen at 2007-7-4 12:38:51 > top of Java-index,Development Tools,Java Tools...