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">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Chapter 7. Databases</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="baseapi.html" title="Part II. Programming with the Base API" />
11 <link rel="prev" href="baseapi.html" title="Part II. Programming with the Base API" />
12 <link rel="next" href="coredbclose.html" title="Closing Databases" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">Chapter 7. Databases</th>
24 <td width="20%" align="left"><a accesskey="p" href="baseapi.html">Prev</a> </td>
25 <th width="60%" align="center">Part II. Programming with the Base API</th>
26 <td width="20%" align="right"> <a accesskey="n" href="coredbclose.html">Next</a></td>
31 <div class="chapter" lang="en" xml:lang="en">
32 <div class="titlepage">
35 <h2 class="title"><a id="databases"></a>Chapter 7. Databases</h2>
41 <b>Table of Contents</b>
46 <a href="databases.html#DBOpen">Opening Databases</a>
51 <a href="coredbclose.html">Closing Databases</a>
56 <a href="dbprops.html">Database Properties</a>
61 <a href="DBAdmin.html">Administrative Methods</a>
66 <a href="dbErrorReporting.html">Error Reporting Functions</a>
71 <a href="CoreEnvUsage.html">Managing Databases in Environments</a>
76 <a href="CoreJavaUsage.html">Database Example</a>
81 <p>In Berkeley DB, a database is a collection of <span class="emphasis"><em>records</em></span>. Records,
82 in turn, consist of key/data pairings.
85 Conceptually, you can think of a
86 <code class="classname">Database</code>
88 as containing a two-column table where column 1 contains a key and column 2
89 contains data. Both the key and the data are managed using
90 <code class="classname">DatabaseEntry</code>
93 <span>class instances</span>
95 (see <a class="xref" href="DBEntry.html" title="Chapter 8. Database Records">Database Records</a> for details on this
98 So, fundamentally, using a DB
99 <code class="classname">Database</code>
101 involves putting, getting, and deleting database records, which in turns involves efficiently
103 <span>encapsulated by </span>
106 <code class="classname">DatabaseEntry</code>
110 <span>objects.</span>
112 The next several chapters of this book are dedicated to those activities.
115 Also, note that in the previous section of this book, <a class="xref" href="dpl.html" title="Part I. Programming with the Direct Persistence Layer">Programming with the Direct Persistence Layer</a>,
116 we described the DPL The DPL handles all database management
117 for you, including creating all primary and secondary databases as is
118 required by your application. That said, if you are using the DPL
119 you can access the underlying database for a given index if
120 necessary. See the Javadoc for the DPL for more information.
122 <div class="sect1" lang="en" xml:lang="en">
123 <div class="titlepage">
126 <h2 class="title" style="clear: both"><a id="DBOpen"></a>Opening Databases</h2>
131 You open a database by instantiating a <code class="classname">Database</code>
135 Note that by default, DB does not create databases if they do not already exist.
136 To override this behavior, set the <a class="link" href="dbprops.html" title="Database Properties">creation property</a> to true.
139 The following code fragment illustrates a database open:
142 <a id="java_db1"></a>
143 <pre class="programlisting">package db.GettingStarted;
145 import com.sleepycat.db.DatabaseException;
146 import com.sleepycat.db.Database;
147 import com.sleepycat.db.DatabaseConfig;
149 import java.io.FileNotFoundException;
152 Database myDatabase = null;
157 // Open the database. Create it if it does not already exist.
158 DatabaseConfig dbConfig = new DatabaseConfig();
159 dbConfig.setAllowCreate(true);
160 myDatabase = new Database ("sampleDatabase.db",
163 } catch (DatabaseException dbe) {
164 // Exception handling goes here
165 } catch (FileNotFoundException fnfe) {
166 // Exception handling goes here
170 <div class="navfooter">
172 <table width="100%" summary="Navigation footer">
174 <td width="40%" align="left"><a accesskey="p" href="baseapi.html">Prev</a> </td>
175 <td width="20%" align="center">
176 <a accesskey="u" href="baseapi.html">Up</a>
178 <td width="40%" align="right"> <a accesskey="n" href="coredbclose.html">Next</a></td>
181 <td width="40%" align="left" valign="top">Part II. Programming with the Base API </td>
182 <td width="20%" align="center">
183 <a accesskey="h" href="index.html">Home</a>
185 <td width="40%" align="right" valign="top"> Closing Databases</td>