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

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();
rs.next();
numOrders[0] = rs.getInt(1);
rs.close();
conn.close();
}
In the SPJ environment, the ORDERS table is qualified by default with the same schema as the
SPJ, SALES.
The default behavior takes effect only when getConnection() does not contain schema
properties. Schema property values in getConnection() have higher precedence over the
default behavior. To override the default schema name and associate a database connection with
a different schema, specify the schema property during connection creation. For example,
getConnection() in this SPJ method specifies the schema, SALES2, which overrides the default
schema, SALES:
public static void numDailyOrders(Date date,
int[] numOrders)
throws SQLException
{
Properties prop = new Properties();
prop.setProperty("schema", "SALES2");
Connection conn = DriverManager.getConnection("jdbc:default:connection", prop);
PreparedStatement getNumOrders =
conn.prepareStatement("SELECT COUNT(order_date) " +
"FROM orders " +
"WHERE order_date = ?");
getNumOrders.setDate(1, date);
ResultSet rs = getNumOrders.executeQuery();
rs.next();
numOrders[0] = rs.getInt(1);
rs.close();
conn.close();
}
Be aware that overriding the default values by using getConnection()requires you to hard-code
the schema name and might make SPJ methods less portable across systems.
30 Developing SPJ Methods