1<!--$Id: faq.so,v 1.16 2007/07/11 11:13:30 mjc 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: Java FAQ</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<a name="2"><!--meow--></a><a name="3"><!--meow--></a> 12<table width="100%"><tr valign=top> 13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Java API</dl></b></td> 14<td align=right><a href="../java/program.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../arch/bigpic.html"><img src="../../images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Java FAQ</b></p> 17<ol> 18<p><li><b>On what platforms is the Berkeley DB Java API supported?</b> 19<p>All platforms supported by Berkeley DB that have a JVM compatible with J2SE 201.4 or above.</p> 21<p><li><b>How does the Berkeley DB Java API relate to the J2EE standard?</b> 22<p>The Berkeley DB Java API does not currently implement any part of the J2EE 23standard. That said, it does implement the implicit standard for Java 24<a href="http://java.sun.com/j2se/1.5.0/docs/guide/collections/">Java Collections</a>. The concept of a transaction exists in several 25Java packages (J2EE, XA, JINI to name a few). Support for these APIs 26will be added based on demand in future versions of Berkeley DB.</p> 27<p><li><b>How should I incorporate db.jar and the db native library into 28a Tomcat or other J2EE application servers?</b> 29<p>Tomcat and other J2EE application servers have the ability to rebuild 30and reload code automatically. When using Tomcat this is the case when 31"reloadable" is set to "true". If your WAR file includes the db.jar it 32too will be reloaded each time your code is reloaded. This causes 33exceptions as the native library can't be loaded more than once and 34there is no way to unload native code. The solution is to place the 35db.jar in $TOMCAT_HOME/common/lib and let Tomcat load that library once 36at start time rather than putting it into the WAR that gets reloaded 37over and over.</p> 38<p><li><b>Can I use the Berkeley DB Java API from within a EJB, a Servlet or a 39JSP page?</b> 40<p>Yes. The Berkeley DB Java API can be used from within all the popular J2EE 41application servers in many different ways.</p> 42<p><li><b>During one of the first calls to the Berkeley DB Java API, a 43DbException is thrown with a "Bad file number" or "Bad file descriptor" 44message.</b> 45<p>There are known large-file support bugs under JNI in various releases 46of the JDK. Please upgrade to the latest release of the JDK, and, if 47that does not solve the problem, disable big file support using the 48--disable-largefile configuration option.</p> 49<p><li><b>How can I use native methods from a debug build of the 50Java library?</b> 51<p>Set Java's library path so that the debug version of Berkeley DB's Java 52library appears, but the release version does not. Berkeley DB tries to load 53the release library first, and if that fails tries the debug library.</p> 54<p><li><b>Why is ClassNotFoundException thrown when adding a record to 55the database, when a SerialBinding is used?</b> 56<p>This problem occurs if you copy the db.jar file into the Java extensions 57(ext) directory. This will cause the database code to run under the 58System class loader, and it won't be able to find your application 59classes.</p> 60<p>You'll have to actually remove db.jar from the Java extension directory. 61If you have more than one installation of Java, be sure to remove it 62from all of them. This is necessary even if db.jar is specified in the 63classpath.</p> 64<p>An example of the exception is:</p> 65<blockquote><pre>collections.ship.basic.SupplierKey 66at java.net.URLClassLoader$1.run(Unknown Source) 67at java.security.AccessController.doPrivileged(Native Method) 68at java.net.URLClassLoader.findClass(Unknown Source) 69at java.lang.ClassLoader.loadClass(Unknown Source) 70at java.lang.ClassLoader.loadClass(Unknown Source) 71at java.lang.ClassLoader.loadClassInternal(Unknown Source) 72at java.lang.Class.forName0(Native Method) 73at java.lang.Class.forName(Unknown Source) 74at com.sleepycat.bind.serial.StoredClassCatalog.getClassInfo(StoredClassCatalog.java:211) 75...</pre></blockquote> 76<p><li><b>I'm upgrading my Java application to Berkeley DB 4.3. Can I use the 77com.sleepycat.db.internal package rather than porting my code to the new 78API?</b> 79<p>While it is possible to use the low-level API from applications, there 80are some caveats that should be considered when upgrading. The first is 81that the internal API depends on some classes in the public API such as 82DatabaseEntry.</p> 83<p>In addition, the internal API is closer to the C API and doesn't have 84some of the default settings that were part of the earlier Java API. 85For example, applications will need to set the DB_THREAD flag explicitly 86if handles are to be used from multiple threads, or subtle errors may 87occur.</p> 88</ol> 89<table width="100%"><tr><td><br></td><td align=right><a href="../java/program.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../arch/bigpic.html"><img src="../../images/next.gif" alt="Next"></a> 90</td></tr></table> 91<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 92</body> 93</html> 94