Closing Databases
Prev | Chapter 7. Databases | Next

## Closing Databases

Once you are done using the database, you must close it. You use the method to do this.

Closing a database causes it to become unusable until it is opened again. Note that you should make sure that any open cursors are closed before closing your database. Active cursors during a database close can cause unexpected results, especially if any of those cursors are writing to the database. You should always make sure that all your database accesses have completed before closing your database.

Cursors are described in Using Cursors later in this manual.

Be aware that when you close the last open handle for a database, then by default its cache is flushed to disk. This means that any information that has been modified in the cache is guaranteed to be written to disk when the last handle is closed. You can manually perform this operation using the `Database.sync()` method, but for normal shutdown operations it is not necessary. For more information about syncing your cache, see Data Persistence.

The following code fragment illustrates a database close:

    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Database;

    ...

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

Prev | Up | Next
Chapter 7. Databases | Home | Database Properties