Neoview Guide to Stored Procedures in Java (R2.3, R2.4)
TOTALPRICE Procedure
The TOTALPRICE procedure accepts the quantity, shipping speed, and price of an item, calculates
the total price, including tax and shipping charges, and returns the total price to an input/output
parameter.
Java Method: totalPrice()
Example A-5 totalPrice() Method
public static void totalPrice(BigDecimal qtyOrdered,
String shippingSpeed,
BigDecimal[] price)
throws SQLException
{
BigDecimal shipcharge = new BigDecimal(0);
if (shippingSpeed.equals("economy"))
{
shipcharge = new BigDecimal(1.95);
}
else if (shippingSpeed.equals("standard"))
{
shipcharge = new BigDecimal(4.99);
}
else if (shippingSpeed.equals("nextday"))
{
shipcharge = new BigDecimal(14.99);
}
else
{
throw new
SQLException ("Invalid value for shipping speed. " +
"Retry the CALL statement using " +
"'economy' for 7 to 9 days," +
"'standard' for 3 to 5 days, or " +
"'nextday' for one day.", "38002" );
}
BigDecimal subtotal = price[0].multiply(qtyOrdered);
BigDecimal tax = new BigDecimal(0.0825);
BigDecimal taxcharge = subtotal.multiply(tax);
BigDecimal charges = taxcharge.add(shipcharge);
price[0] = subtotal.add(charges);
}
Creating the Procedure: TOTALPRICE
To create this procedure in the SALES schema, upload the Sales.jar file to the Neoview
platform, navigate to the SALES schema in DB Admin, and then enter or select these values in
the Create Procedure Wizard of DB Admin. For instructions, see “Uploading SPJ JAR Files to
the Neoview Platform” (page 35) and “Creating SPJs” (page 43).
totalpriceName:
Sales.jar > Sales > totalPriceCode:
84 Sample SPJs