Neoview Guide to Stored Procedures in Java (R2.3, R2.4)
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.
Exception Handling
For SPJ methods that access a Neoview database, no special code is necessary for handling
exceptions. If an SQL operation fails inside an SPJ, the error message associated with the failure
is returned to the application that issues the CALL statement.
Handling Java Exceptions
If an SPJ method returns an uncaught Java exception or an uncaught chain of
java.sql.SQLException objects, Neoview SQL converts each Java exception object into an
SQL error condition, and the CALL statement fails. Each SQL error condition contains the message
text associated with one Java exception object.
If an SPJ method catches and handles exceptions itself, those exceptions do not affect SQL
processing.
User-Defined Exceptions
The SQLSTATE values 38001 to 38999 are reserved for you to define your own error conditions
that SPJ methods can return. By coding your SPJ method to throw a java.sql.SQLException
object, you cause the CALL statement to fail with a specific user-defined SQLSTATE value and
your own error message text.
32 Developing SPJ Methods