Friday, June 23, 2006

Berkeley DB:Part Two

1. Code for exception handing

try
{

}
catch (DatabaseException e)
{
}


2. Errno values, if the errno values are greater than zero then a system error occurred. Special error values like the key and the data being searched is not found results in a error withe negative value.

3. Key and Data of records managed by DatabaseEntry class.

DatabaseConfig class allows setting the properties of the database,
package db.GettingStarted;
import com.sleepycat.db.Database;
import com.sleepycat.db.DatabaseConfig;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.DatabaseType;
import java.io.FileNotFoundException;
...
Database myDatabase = null;
try {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setSortedDuplicates(true);
dbConfig.setType(DatabaseType.BTREE);
myDatabase = new Database("sampleDatabase.db",
null,
dbConfig);

if (myDatabase != null)
myDatabase.close();

} catch (DatabaseException dbe) {
// Exception handling goes here.
} catch (FileNotFoundException fnfe) {
// Exception handling goes here
}

No comments: