1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6    <title>Closing Databases</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" />
9    <link rel="home" href="index.html" title="Getting Started with Berkeley DB" />
10    <link rel="up" href="DB.html" title="Chapter��7.��Databases" />
11    <link rel="previous" href="DB.html" title="Chapter��7.��Databases" />
12    <link rel="next" href="DBConfig.html" title="Database Properties" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Closing Databases</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="DB.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��7.��Databases</th>
23          <td width="20%" align="right">��<a accesskey="n" href="DBConfig.html">Next</a></td>
24        </tr>
25      </table>
26      <hr />
27    </div>
28    <div class="sect1" lang="en" xml:lang="en">
29      <div class="titlepage">
30        <div>
31          <div>
32            <h2 class="title" style="clear: both"><a id="coredbclose"></a>Closing Databases</h2>
33          </div>
34        </div>
35        <div></div>
36      </div>
37      <p>
38        Once you are done using the database, you must close it. You use the
39        
40        
41        method to do this.
42    </p>
43      <p>
44        Closing a database causes it to become unusable until it is opened
45        again. Note that you should make sure that any open cursors are closed
46        before closing your database.  Active cursors during a database
47        close can cause unexpected results, especially if any of those cursors are
48        writing to the database. You should always make sure that all your
49        database accesses have completed before closing your database.
50    </p>
51      <p>
52        Cursors are described in <a href="Cursors.html">Using Cursors</a> later in this manual.
53    </p>
54      <p>
55        Be aware that when you close the last open handle 
56        for a database, then by default its cache is flushed to disk.
57        This means that any information that has
58        been modified in the cache is guaranteed to be written to disk when the
59        last handle is closed. You can manually perform this operation using
60        the 
61        
62        
63        <tt class="methodname">Database.sync()</tt>
64        method, but for normal shutdown operations it is not necessary.
65        For more information about syncing your cache, see 
66        <a href="usingDbt.html#datapersist">Data Persistence</a>.
67     </p>
68      <p>The following code fragment illustrates a database close:</p>
69      <a id="java_db2"></a>
70      <pre class="programlisting">import com.sleepycat.db.DatabaseException;
71import com.sleepycat.db.Database;
72
73...
74
75try {
76        if (myDatabase != null) {
77            myDatabase.close();
78        }
79} catch (DatabaseException dbe) {
80    // Exception handling goes here
81} </pre>
82    </div>
83    <div class="navfooter">
84      <hr />
85      <table width="100%" summary="Navigation footer">
86        <tr>
87          <td width="40%" align="left"><a accesskey="p" href="DB.html">Prev</a>��</td>
88          <td width="20%" align="center">
89            <a accesskey="u" href="DB.html">Up</a>
90          </td>
91          <td width="40%" align="right">��<a accesskey="n" href="DBConfig.html">Next</a></td>
92        </tr>
93        <tr>
94          <td width="40%" align="left" valign="top">Chapter��7.��Databases��</td>
95          <td width="20%" align="center">
96            <a accesskey="h" href="index.html">Home</a>
97          </td>
98          <td width="40%" align="right" valign="top">��Database Properties</td>
99        </tr>
100      </table>
101    </div>
102  </body>
103</html>
104