Library Version 12.1.6.0

Database Properties
Prev | Chapter 7. Databases | Next

## Database Properties

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. By default, byte for byte comparison is used. 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 an error return from the put call. Note that this property can be set only at database creation time. Default is `false`.

  Note that your database must not support duplicates if it is to be associated with one or more secondary indices. Secondaries are described in Secondary Databases.

- `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`. Note that a database cannot support transactions if the environment is non-transactional.

For example:

    package je.gettingStarted;

    import com.sleepycat.je.DatabaseException;
    import com.sleepycat.je.Database;
    import com.sleepycat.je.DatabaseConfig;

    ...
    // Environment open omitted for brevity
    ...

    Database myDatabase = null;
    try {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        dbConfig.setSortedDuplicates(true);
        myDatabase =
            myDbEnv.openDatabase(null,
                                 "sampleDatabase",
                                 dbConfig);
    } catch (DatabaseException dbe) {
        // Exception handling goes here.
    }

Prev | Up | Next
Chapter 7. Databases | Home | Administrative Methods