Neoview Guide to Stored Procedures in Java (R2.5)
ADJUSTSALARY Procedure
The ADJUSTSALARY procedure 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.
Java Method: adjustSalary()
Example A-9 adjustSalary() Method
public static void adjustSalary(BigDecimal empNum,
double percent,
BigDecimal[] newSalary)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement setSalary =
conn.prepareStatement("UPDATE persnl.employee " +
"SET salary = salary * (1 + (? / 100)) " +
"WHERE empnum = ?");
PreparedStatement getSalary =
conn.prepareStatement("SELECT salary " +
"FROM 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();
}
Creating the Procedure: ADJUSTSALARY
To create this procedure in the PERSNL schema, upload the Payroll.jar file to the Neoview
platform, navigate to the PERSNL schema in HPDM, and then enter or select these values in the
Create Procedure dialog box of HPDM. For more information, see the HP Database Manager
(HPDM) User Guide.
adjustsalaryName:
Payroll.jar > Payroll > adjustSalaryCode:
Procedures in the PERSNL Schema 85