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