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

Accessing a Neoview Database
SPJ methods that access a Neoview database must be from a Java class that uses JDBC method
calls. Follow these guidelines when writing an SPJ method that accesses a Neoview database:
“Use of java.sql.Connection Objects” (page 28)
“Using JDBC Method Calls” (page 29)
“Referring to Database Objects in an SPJ Method” (page 30)
“Exception Handling” (page 31)
Use of java.sql.Connection Objects
Neoview SQL supports a default connection in an SPJ execution environment, which has a data
source URL of "jdbc:default:connection". For example:
Connection conn = DriverManager.getConnection("jdbc:default:connection");
java.sql.Connection objects that use the "jdbc:default:connection" URL are portable
to the Neoview platform from other database management systems (DBMSs).
Closing Default Connections
Neoview SQL controls default connections in the SPJ environment and closes default connections
when they are no longer needed. Therefore, you do not need to use the close() method in an
SPJ method to explicitly close a default connection when the connection is no longer needed.
IMPORTANT: If an SPJ method returns result sets, you should not explicitly close the default
connection. Neoview SQL closes the connection used to return result sets after it finishes
processing the result sets. If an SPJ method closes the connection on which the result sets are
being returned, those result sets will be lost, and the calling application will not be able to process
them. The JVM does not return an error or warning when the connection is closed.
A default connection that is acquired when an SPJ method executes does not necessarily remain
open for future invocations of the SPJ method. Therefore, do not store default connections in
static variables for future use.
Default Connection URL
The default connection URL, "jdbc:default:connection", is invalid when the Java method
is invoked outside the DBMS, such as when you execute the Java method in a client application.
To write an SPJ method that operates in a DBMS, in a client application, or both, without having
to change and recompile the code, use the sqlj.defaultconnection system property:
String s = System.property("sqlj.defaultconnection");
if (s == null) {
s = other-url;
}
Connection c = DriverManager.getConnection(s);
The value of sqlj.defaultconnection is "jdbc:default:connection" in a DBMS and
null outside a DBMS.
Connection Pooling
Connection pooling, where a cache of database connections is assigned to a client session and
reused, is enabled by default in the SPJ environment. The SPJ environment sets the initial
connection pool size to 1, but it does not limit the number of connections an SPJ method can
make. The SPJ environment also sets the minimum connection pool size to 1 so that there is
always at least one connection available in the pool. The default settings in the SPJ environment
are:
28 Developing SPJ Methods