SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)
The Inventory.java source file in SampleSPJs.jar contains the code shown in Example 3.
Example 3 Inventory.java-The Inventory Class
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:default:connection");
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();
}
public static void supplyQuantities(int[] avgQty,
int[] minQty,
int[] maxQty)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement getQty =
conn.prepareStatement("SELECT AVG(qty_on_hand), " +
" MIN(qty_on_hand), " +
" MAX(qty_on_hand) " +
"FROM samdbcat.invent.partloc");
ResultSet rs = getQty.executeQuery();
rs.next();
avgQty[0] = rs.getInt(1);
minQty[0] = rs.getInt(2);
maxQty[0] = rs.getInt(3);
rs.close();
conn.close();
}
}
The createprocs.sql File
CREATE PROCEDURE statements register SPJ methods in an SQL/MX database. Before registering
the methods described in Class Files and Java Methods (page 106), you must compile the Java
source files into class files. See Compiling Java Classes (page 58).
An OBEY command file named createprocs.sql in SampleSPJs.jar contains the CREATE
PROCEDURE statements shown in Example 4.
The createprocs.sql File 111










