SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)
"using a number from 1 to 12 " +
"to represent the month.", "38001");
}
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement getNumOrders =
conn.prepareStatement("SELECT COUNT(month(order_date))" +
"FROM samdbcat.sales.orders "+
"WHERE month(order_date) = ?");
getNumOrders.setInt(1, month);
ResultSet rs = getNumOrders.executeQuery();
rs.next();
numOrders[0] = rs.getInt(1);
rs.close();
conn.close();
}
public static voidtotalPrice(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);
}
}
Payroll Class
The Payroll class contains these SPJ methods, which are useful for managing personnel data:
• The adjustSalary() method accepts an employee number and a percentage value and
updates the employee's salary in the database based on this value. This method also returns
the updated salary to an output parameter.
• The employeeJob() method accepts an employee number and returns a job code or null
value to an output parameter.
The Payroll.java source file in SampleSPJs.jar contains the code shown in Example 2.
Class Files and Java Methods 109










