javaberkeley-db-je

how to read existing jdb file java berkeley db


I am trying to read a generated database (*.jdb) file.

For creating a new database I use:

    storeConfig_ = new StoreConfig();
    storeConfig_.setAllowCreate(true);

What StoreConfig parameters must I pass in to read an already existing *.jdb file?


Solution

    1. Configure the environment.
    2. Create environment defining it's location.
    3. Create new EntityStore using the predefined DAO.
    4. Then you can access the database using the index.

      EnvironmentConfig envConfig = new EnvironmentConfig();
      
      try {
          myDbEnvironment_ = new Environment(new File(getDatabasePathString()), envConfig);
      } catch (DatabaseException e) {
          e.printStackTrace();
      }
      DAO.store_ = new EntityStore(environment, "EntityStore", new StoreConfig());
      Index_ = store_.getPrimaryIndex(String.class, Page.class);