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 Database Environments</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Getting Started with Berkeley DB" /> 10 <link rel="up" href="Env.html" title="Chapter��2.��Database Environments" /> 11 <link rel="prev" href="Env.html" title="Chapter��2.��Database Environments" /> 12 <link rel="next" href="EnvProps.html" title="Environment 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 Database Environments</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="Env.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.��Database Environments</th> 23 <td width="20%" align="right">��<a accesskey="n" href="EnvProps.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="EnvClose"></a>Closing Database Environments</h2> 33 </div> 34 </div> 35 </div> 36 <p> 37 You close your environment by calling the 38 <code class="methodname">Environment.close()</code> 39 method. This method performs a checkpoint, so it is not necessary to perform a sync or a checkpoint explicitly 40 before calling it. For information on checkpoints, see the 41 <em class="citetitle">Berkeley DB Java Edition Getting Started with Transaction Processing</em> guide. 42 For information on syncs, see 43 44 45 <span> 46 the <em class="citetitle">Getting Started with Transaction Processing for Java</em> guide. 47 </span> 48 </p> 49 <pre class="programlisting">import com.sleepycat.db.DatabaseException; 50 51import com.sleepycat.db.Environment; 52 53... 54 55try { 56 if (myDbEnvironment != null) { 57 myDbEnvironment.close(); 58 } 59} catch (DatabaseException dbe) { 60 // Exception handling goes here 61} </pre> 62 <p>You should close your environment(s) only after all other 63 database activities have completed and you have closed any databases 64 currently opened in the environment.</p> 65 <p> 66 Closing the last environment handle in your application causes all 67 internal data structures to be 68 69 <span> 70 released. 71 </span> 72 73 74 75 If there are any opened databases or stores, 76 then DB will complain before closing them as well. 77 At this time, any open cursors are also closed, and any on-going transactions are aborted. 78 </p> 79 </div> 80 <div class="navfooter"> 81 <hr /> 82 <table width="100%" summary="Navigation footer"> 83 <tr> 84 <td width="40%" align="left"><a accesskey="p" href="Env.html">Prev</a>��</td> 85 <td width="20%" align="center"> 86 <a accesskey="u" href="Env.html">Up</a> 87 </td> 88 <td width="40%" align="right">��<a accesskey="n" href="EnvProps.html">Next</a></td> 89 </tr> 90 <tr> 91 <td width="40%" align="left" valign="top">Chapter��2.��Database Environments��</td> 92 <td width="20%" align="center"> 93 <a accesskey="h" href="index.html">Home</a> 94 </td> 95 <td width="40%" align="right" valign="top">��Environment Properties</td> 96 </tr> 97 </table> 98 </div> 99 </body> 100</html> 101