Neoview Guide to Stored Procedures in Java (R2.2)
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 23).
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
c. Package the SPJ class file in a JAR file:
jar cvf Payroll.jar Payroll.class
If the SPJ class refers to other classes, package the other classes in the same JAR file as
the SPJ class:
jar cvf Payroll.jar Payroll.class other.class
For details, see Chapter 3 (page 25).
How Do I Use SPJs in a Neoview Database? 21