1<!--$Id: db_cxx.so,v 11.9 2000/03/22 22:02:14 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Release 3.0: the Db class for C++ and Java</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></b></td> 13<td align=right><a href="../upgrade.3.0/dbenv_cxx.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../upgrade.3.0/cxx.html"><img src="../../images/next.gif" alt="Next"></a> 14</td></tr></table> 15<p align=center><b>Release 3.0: the Db class for C++ and Java</b></p> 16<p>The static Db::open method and the DbInfo class have been removed in the 17Berkeley DB 3.0 release. The way to open a database file is to use the new Db 18constructor with two arguments, followed by set_XXX methods to configure 19the Db object, and finally a call to the new (nonstatic) Db::open(). In 20comparing the Berkeley DB 3.0 release open method with the 2.X static open 21method, the second argument is new. It is a database name, which can 22be null. The DbEnv argument has been removed, as the environment is now 23specified in the constructor. The open method no longer returns a Db, 24since it operates on one.</p> 25<p>Here's a C++ example opening a Berkeley DB database using the 2.X interface:</p> 26<blockquote><pre>// Note: by default, errors are thrown as exceptions 27Db *table; 28Db::open("lookup.db", DB_BTREE, DB_CREATE, 0644, dbenv, 0, &table);</pre></blockquote> 29<p>In the Berkeley DB 3.0 release, this code would be written as:</p> 30<blockquote><pre>// Note: by default, errors are thrown as exceptions 31Db *table = new Db(dbenv, 0); 32table->open("lookup.db", NULL, DB_BTREE, DB_CREATE, 0644);</pre></blockquote> 33<p>Here's a Java example opening a Berkeley DB database using the 2.X interface:</p> 34<blockquote><pre>// Note: errors are thrown as exceptions 35Db table = Db.open("lookup.db", Db.DB_BTREE, Db.DB_CREATE, 0644, dbenv, 0);</pre></blockquote> 36<p>In the Berkeley DB 3.0 release, this code would be written as:</p> 37<blockquote><pre>// Note: errors are thrown as exceptions 38Db table = new Db(dbenv, 0); 39table.open("lookup.db", null, Db.DB_BTREE, Db.DB_CREATE, 0644);</pre></blockquote> 40<p>Note that if the dbenv argument is null, the database will not exist 41within an environment.</p> 42<table width="100%"><tr><td><br></td><td align=right><a href="../upgrade.3.0/dbenv_cxx.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../upgrade.3.0/cxx.html"><img src="../../images/next.gif" alt="Next"></a> 43</td></tr></table> 44<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 45</body> 46</html> 47