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

The SPJ environment sets the initial connection pool size to 1, but it does not limit the number of
connections an SPJ method can make. The SPJ environment also sets the minimum connection pool
size to 1 so that there is always at least one connection available in the pool. The default settings
in the SPJ environment are:
maxPoolSize=0
minPoolSize=1
initialPoolSize=1
To change these settings, use the properties parameter of the
DriverManager.getConnection() method as shown below:
java.util.Properties props = new Properties();
props.setProperty("maxPoolSize", "10");
props.setProperty("minPoolSize", "5");
props.setProperty("initialPoolSize", "5");
Connection conn =
DriverManager.getConnection("jdbc:default:connection", props);
For more information on JDBC Type 2 driver properties, see the JDBC Type 2 Driver Programmer's
Reference for SQL/MX Release 3.2.
JDBC/MX-Based Java Method
A JDBC/MX-based Java method is from a Java program that contains SQL/MX statements in
JDBC/MX method calls. You can use this type of method to create an SPJ that performs SQL
operations on an SQL/MP or SQL/MX database.
For example, the adjustSalary() method in the Payroll class adjusts an employee's salary
in the EMPLOYEE table:
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();
}
}
You do not have to explicitly load the JDBC/MX driver before establishing a connection to the
database. The SQL/MX UDR server automatically loads the JDBC/MX driver when the SPJ is called.
54 Writing SPJ Methods