Closing a connection to a database
When you close a connection to a database, JDBC and SQLJ resources are automatically released. Typically, a connection to a database is closed when the task ends.
For performance reasons, an application might leave the JDBC connection open for a subsequent user of the same JVM to use. If the JDBC connection is left open, the application must ensure that JDBC resources are not leaked over time.
If the application leaves the JDBC or SQLJ connection open, the
application must do the following:
- Ensure that JDBC and SQLJ resources are released.
- Recover following a Db2® SIGNON for the underlying Db2 connection.
- Recycle the cached connection if it become invalid; for example, StaleConnection, SQLCODE=4499.
If connections are cached, you are recommended to include logic in your application that recycles the connection after a given number of transactions. Recycling cached connections protects against resource leakage.