DB2 Version 10.1 for Linux, UNIX, and Windows

Closing the connection to a data source in an SQLJ application

When you have finished with a connection to a data source, you need to close the connection to the data source. Doing so releases the data server resources and SQLJ resources for the associated ConnectionContext object immediately.

If you do not close a ConnectionContext object after you use it, unexpected behavior might occur if a Java™ finalizer closes the ConnectionContext object. Examples of the unexpected behavior are:
To close the connection to the data source, use one of the ConnectionContext.close methods.
The following code closes the connection context, but does not close the connection to the data source.
…
ctx = new EzSqljctx(con0);          // Create a connection context object
                                    // from JDBC connection con0
…                                   // Perform various SQL operations 
 EzSqljctx.close(ConnectionContext.KEEP_CONNECTION);
                                    // Close the connection context but keep
                                    // the connection to the data source open