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 connection context object’s
DB2 and SQLJ resources immediately.
To close the connection to the data source, use one of the ConnectionContext.close
methods.
v If you execute ConnectionContext.close() or
ConnectionContext.close(ConnectionContext.CLOSE_CONNECTION), the connection
context, as well as the connection to the data source, are closed.
v If you execute ConnectionContext.close(ConnectionContext.KEEP_CONNECTION)
the connection context is closed, but the connection to the data source is not.
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
Related concepts
“Example of a simple SQLJ application” on page 101
Related tasks
“Connecting to a data source using SQLJ” on page 103
156 Application Programming Guide and Reference for Java
™