SQL/MX Guide to Stored Procedures in Java (G06.24+, H06.03+)

Sample SPJs
HP NonStop SQL/MX Guide to Stored Procedures in Java523727-004
A-9
Inventory Class
Inventory Class
The Inventory class contains these SPJ methods, which are useful for tracking parts
and suppliers:
The supplierInfo() method accepts a supplier number and returns the
supplier’s name, street, city, state, and post code to separate output parameters.
The supplyQuantities() method returns the average, minimum, and
maximum quantities of available parts in inventory to separate output parameters.
The Inventory.java source file in SampleSPJs.jar contains the code shown in
Example A-3.
Example A-3. Inventory.java—The Inventory Class (page 1 of 2)
import java.sql.*;
import java.math.*;
public class Inventory
{
public static void
supplierInfo(BigDecimal suppNum,
String[] suppName,
String[] streetAddr,
String[] cityName,
String[] stateName,
String[] postCode)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:sqlmx:");
PreparedStatement getSupplier =
conn.prepareStatement("SELECT suppname, street, city, " +
" state, postcode " +
"FROM samdbcat.invent.supplier " +
"WHERE suppnum = ?");
getSupplier.setBigDecimal(1, suppNum);
ResultSet rs = getSupplier.executeQuery();
rs.next();
suppName[0] = rs.getString(1);
streetAddr[0] = rs.getString(2);
cityName[0] = rs.getString(3);
stateName[0] = rs.getString(4);
postCode[0] = rs.getString(5);
rs.close();
conn.close();
}