Neoview Guide to Stored Procedures in Java (R2.3, R2.4)
about the Neoview JDBC Type 4 Driver, see the Neoview JDBC Type 4 Driver Programmer’s Reference
and the Neoview JDBC Type 4 Driver API Reference.
NOTE: You do not have to explicitly load the JDBC driver before establishing a connection to
the Neoview database. Neoview SQL automatically loads the JDBC driver when the SPJ is called.
Here is an example of an SPJ method, adjustSalary(), that uses JDBC method calls to adjust
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 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();
}
}
For other examples of SPJ methods, see Appendix A (page 77).
Referring to Database Objects in an SPJ Method
In an SPJ method, you can refer to SQL database objects by specifying two-part ANSI names that
include the schema and object name. For more information about database object names, see the
Neoview SQL Reference Manual.
Neoview SQL propagates the name of the schema where the SPJ is registered to the SPJ
environment. By default, database connections created in the SPJ method are associated with
that schema, meaning that unqualified database objects with one-part names in the SPJ method
are qualified with the same schema name as the SPJ. For example, this SPJ method, which is
registered as an SPJ in the SALES schema, refers to the unqualified database object, ORDERS:
public static void numDailyOrders(Date date,
int[] numOrders)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement getNumOrders =
conn.prepareStatement("SELECT COUNT(order_date) " +
"FROM orders " +
"WHERE order_date = ?");
getNumOrders.setDate(1, date);
ResultSet rs = getNumOrders.executeQuery();
Accessing a Neoview Database 31