You can set database properties using the DatabaseConfig class. For each of the properties that you can set, there is a corresponding getter method. Also, you can always retrieve the DatabaseConfig object used by your database using the Database.getConfig() method.
The database properties that you can set are:
DatabaseConfig.setAllowCreate()
If true, the database is created when it is opened. If false, the database open fails if the database does not exist. This property has no meaning if the database currently exists. Default is false.
DatabaseConfig.setBtreeComparator()
Sets the class that is used to compare the keys found on two database records. This class is used to determine the sort order for two records in the database. For more information, see Using Comparators.
DatabaseConfig.setDuplicateComparator()
Sets the class that is used to compare two duplicate records in the database. For more information, see Using Comparators.
DatabaseConfig.setSortedDuplicates()
If true, duplicate records are allowed in the database. If this value is false, then putting a duplicate record into the database results in the replacement of the old record with the new record. Note that this property can be set only at database creation time. Default is false.
DatabaseConfig.setExclusiveCreate()
If true, the database open fails if the database currently exists. That is, the open must result in the creation of a new database. Default is false.
DatabaseConfig.setReadOnly()
If true, the database is opened for read activities only. Default is false.
DatabaseConfig.setTransactional()
If true, the database supports transactions. Default is false.
For example:
import com.sleepycat.je.DatabaseException; import com.sleepycat.je.Database; import com.sleepycat.je.DatabaseConfig; ... try { DatabaseConfig dbConfig = new DatabaseConfig(); dbConfig.setAllowCreate(true); dbConfig.setSortedDuplicates(true); Database myDatabase = myDbEnvironment.openDatabase(null, "sampleDatabase", dbConfig); } catch (DatabaseException dbe) { // Exception handling goes here. }