Neoview Guide to Stored Procedures in Java (R2.3, R2.4)
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).
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. In
fact, 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.
A default connection that is acquired when an SPJ method executes is not guaranteed to remain
open for future invocations of the SPJ method. Therefore, do not store default connections in
static variables for future use.
The default connection URL, "jdbc:default:connection", is invalid outside a DBMS, such
as when you execute a Java method in an application. To write an SPJ method that operates in
a DBMS, in an 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, 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:
• maxPoolSize=0
• minPoolSize=1
• initialPoolSize=1
To change these settings, use the properties parameter of the
DriverManager.getConnection() method as shown below:
java.util.Properties props = new Properties();
props.setProperty("maxPoolSize", "10");
props.setProperty("minPoolSize", "5");
props.setProperty("initialPoolSize", "5");
Connection conn = DriverManager.getConnection("jdbc:default:connection", props);
For details about the JDBC Type 4 driver properties, see the HP Neoview JDBC Type 4 Programmer's
Reference.
Using JDBC Method Calls
The Neoview platform uses a JDBC Type 4 driver internally to execute the SQL statements inside
an SPJ method. To enable an SPJ to perform SQL operations on a Neoview database, use JDBC
method calls in the SPJ method. The JDBC method calls must be supported by the JDBC Type 4
driver of the Neoview platform. For example, if you want the SPJ method to operate on a Neoview
Release 2.3 database, use the JDBC API that is supported by Neoview Release 2.3. For information
30 Developing SPJ Methods