Closing Database Environments
Prev | Chapter 2. Database Environments | Next

## Closing Database Environments

You close your environment by calling the `Environment.close()` method. This method performs a checkpoint, so it is not necessary to perform a sync or a checkpoint explicitly before calling it. For information on checkpoints, see the Berkeley DB Java Edition Getting Started with Transaction Processing guide. For information on syncs, see the Getting Started with Transaction Processing for Java guide.

    import com.sleepycat.db.DatabaseException;

    import com.sleepycat.db.Environment;

    ...

    try {
        if (myDbEnvironment != null) {
            myDbEnvironment.close();
        }
    } catch (DatabaseException dbe) {
        // Exception handling goes here
    }

You should close your environment(s) only after all other database activities have completed and you have closed any databases currently opened in the environment.

Closing the last environment handle in your application causes all internal data structures to be released. If there are any opened databases or stores, then DB will complain before closing them as well. At this time, any open cursors are also closed, and any on-going transactions are aborted.

Prev | Up | Next
Chapter 2. Database Environments | Home | Environment Properties