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>Release 3.0: the Db class for C++ and Java</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="Berkeley DB Programmer's Reference Guide" /> 10 <link rel="up" href="upgrade_3_0_toc.html" title="Chapter��33.��Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0" /> 11 <link rel="prev" href="upgrade_3_0_dbenv_cxx.html" title="Release 3.0: the DbEnv class for C++ and Java" /> 12 <link rel="next" href="upgrade_3_0_cxx.html" title="Release 3.0: additional C++ changes" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Release 3.0: the Db class for C++ and Java</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="upgrade_3_0_dbenv_cxx.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��33.��Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0</th> 23 <td width="20%" align="right">��<a accesskey="n" href="upgrade_3_0_cxx.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="upgrade_3_0_db_cxx"></a>Release 3.0: the Db class for C++ and Java</h2> 33 </div> 34 </div> 35 </div> 36 <p>The static Db::open method and the DbInfo class have been removed in the 37Berkeley DB 3.0 release. The way to open a database file is to use the new Db 38constructor with two arguments, followed by set_XXX methods to configure 39the Db object, and finally a call to the new (nonstatic) Db::open(). In 40comparing the Berkeley DB 3.0 release open method with the 2.X static open 41method, the second argument is new. It is a database name, which can 42be null. The DbEnv argument has been removed, as the environment is now 43specified in the constructor. The open method no longer returns a Db, 44since it operates on one.</p> 45 <p>Here's a C++ example opening a Berkeley DB database using the 2.X interface:</p> 46 <pre class="programlisting">// Note: by default, errors are thrown as exceptions 47Db *table; 48Db::open("lookup.db", DB_BTREE, DB_CREATE, 0644, dbenv, 0, &table);</pre> 49 <p>In the Berkeley DB 3.0 release, this code would be written as:</p> 50 <pre class="programlisting">// Note: by default, errors are thrown as exceptions 51Db *table = new Db(dbenv, 0); 52table->open("lookup.db", NULL, DB_BTREE, DB_CREATE, 0644);</pre> 53 <p>Here's a Java example opening a Berkeley DB database using the 2.X interface:</p> 54 <pre class="programlisting">// Note: errors are thrown as exceptions 55Db table = Db.open("lookup.db", Db.DB_BTREE, Db.DB_CREATE, 0644, dbenv, 0);</pre> 56 <p>In the Berkeley DB 3.0 release, this code would be written as:</p> 57 <pre class="programlisting">// Note: errors are thrown as exceptions 58Db table = new Db(dbenv, 0); 59table.open("lookup.db", null, Db.DB_BTREE, Db.DB_CREATE, 0644);</pre> 60 <p>Note that if the dbenv argument is null, the database will not exist 61within an environment.</p> 62 </div> 63 <div class="navfooter"> 64 <hr /> 65 <table width="100%" summary="Navigation footer"> 66 <tr> 67 <td width="40%" align="left"><a accesskey="p" href="upgrade_3_0_dbenv_cxx.html">Prev</a>��</td> 68 <td width="20%" align="center"> 69 <a accesskey="u" href="upgrade_3_0_toc.html">Up</a> 70 </td> 71 <td width="40%" align="right">��<a accesskey="n" href="upgrade_3_0_cxx.html">Next</a></td> 72 </tr> 73 <tr> 74 <td width="40%" align="left" valign="top">Release 3.0: the DbEnv class for C++ and Java��</td> 75 <td width="20%" align="center"> 76 <a accesskey="h" href="index.html">Home</a> 77 </td> 78 <td width="40%" align="right" valign="top">��Release 3.0: additional C++ changes</td> 79 </tr> 80 </table> 81 </div> 82 </body> 83</html> 84