Neoview Guide to Stored Procedures in Java (R2.5)

Using the Java language to implement stored procedures increases development productivity.
Given the popularity of the Java language, you can leverage the existing skill set of Java
programmers to develop SPJs. The portability of the Java language enables you to write and
compile Java class files for SPJs once and deploy them anywhere.
Portability
Because SPJ methods are written in Java, and SPJs conform to the ANSI SQL standard, SPJs are
portable across different database servers. With minimal changes to SPJ methods, you can port
existing SPJ JAR files from another database server to a Neoview platform and register the
methods as stored procedures in a Neoview database. You can also port client applications that
call SPJs in other databases to Neoview SQL with minimal changes to the CALL statements in
the application.
For assistance converting your stored procedures to Neoview SQL, contact your HP account
representative.
How Do I Use SPJs in a Neoview Database?
To use SPJs in a Neoview database:
1. Verify that you have the required software installed on the client workstation. See Chapter 2
(page 21).
2. Develop a Java method to be used as an SPJ:
a. Write a static Java method:
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 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();
}
}
b. Compile the Java source file to produce a class file:
javac Payroll.java
How Do I Use SPJs in a Neoview Database? 19