SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)

Example 2 Payroll.java-The PayrollClass
import java.sql.*;
import java.math.*;
public class Payroll
{
public static void adjustSalary(BigDecimal empNum,
double percent,
BigDecimal[] newSalary)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement setSalary =
conn.prepareStatement("UPDATE samdbcat.persnl.employee" +
"SET salary = salary * (1 + (?/ 100)) " +
"WHERE empnum = ?");
PreparedStatement getSalary =
conn.prepareStatement("SELECT salary " +
"FROM samdbcat.persnl.employee" +
"WHERE empnum = ?");
setSalary.setDouble(1, percent);
setSalary.setBigDecimal(2, empNum);
setSalary.executeUpdate();
getSalary.setBigDecimal(1, empNum);
ResultSet rs = getSalary.executeQuery();
rs.next();
newSalary[0] = rs.getBigDecimal(1);
rs.close();
conn.close();
}
public static void employeeJob(int empNum,
java.lang.Integer[] jobCode)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement getJobcode =
conn.prepareStatement("SELECT jobcode " +
"FROM samdbcat.persnl.employee" +
"WHERE empnum = ?");
getJobcode.setInt(1, empNum);
ResultSet rs = getJobcode.executeQuery();
rs.next();
int num = rs.getInt(1);
if (rs.wasNull())
jobCode[0] = null;
else
jobCode[0] = new Integer(num);
rs.close();
conn.close();
}
}
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.
110 Sample SPJs