Both the Environment and Database classes provide methods that are useful for manipulating databases. These methods are:
Database.getDatabaseName()
Returns the database's name.
String dbName = myDb.getDatabaseName();
Database.getEnvironment()
Returns the Environment that contains this database.
Environment theEnv = myDb.getEnvironment();
Database.truncate()
Deletes every record in the database and optionally returns the number of records that were deleted. Note that it is much less expensive to truncate a database without counting the number of records deleted than it is to truncate and count.
int numDiscarded = myDb.truncate(null, true); // If true, then the number of // records deleted are counted. System.out.println("Discarded " + numDiscarded + " records from database " + myDb.getDatabaseName());
Database.preload()
Preloads the database into the in-memory cache. Optionally takes a long that identifies the maximum number of bytes to load into the cache. If this parameter is not supplied, the maximum memory usage allowed by the evictor thread is used.
myDb.preload(1048576l); // 1024*1024
Environment.getDatabaseNames()
Returns a list of Strings of all the databases contained by the environment.
List myDbNames = myDbEnv.getDatabaseNames(); for(int i=0; i < myDbNames.size(); i++) { System.out.println("Database Name: " + (String)myDbName.get(i)); }
Environment.removeDatabase()
Deletes the database. The database must be closed when you perform this action on it.
String dbName = myDb.getDatabaseName(); myDb.close(); myDbEnv.removeDatabase(null, dbName);
Environment.renameDatabase()
Renames the database. The database must be closed when you perform this action on it.
String oldName = myDb.getDatabaseName(); String newName = new String(oldName + ".new"); myDb.close(); myDbEnv.renameDatabase(null, oldName, newName);