作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有数据库/home/panayk/Desktop/panag_3/panag_3.tld:
$ db_verify /home/panayk/Desktop/panag_3/panag_3.tld
Verification of /home/panayk/Desktop/panag_3/panag_3.tld succeeded.
BerkeleyDB 拒绝打开它。
这是我的导入:
import com.sleepycat.bind.EntryBinding;
import com.sleepycat.bind.serial.SerialBinding;
import com.sleepycat.bind.serial.StoredClassCatalog;
import com.sleepycat.collections.StoredMap;
import com.sleepycat.collections.TransactionRunner;
import com.sleepycat.collections.TransactionWorker;
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
这是我的代码:
final File file = new File(filename);
final String homeDirectoryName = file.getParent();
final File homeDirectory = new File(homeDirectoryName);
LOGGER.info("Opening environment in {}.", homeDirectoryName);
final EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setAllowCreate(true);
final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(false);
environment = new Environment(homeDirectory, environmentConfig);
LOGGER.info("Opening database in {}.", filename);
database = environment.openDatabase(null, filename, dbConfig);
catalog = new StoredClassCatalog(database);
final EntryBinding keyBinding = new SerialBinding(catalog, Object.class);
final EntryBinding valueBinding = new SerialBinding(catalog, Object.class);
map = new StoredMap(database, keyBinding, valueBinding, true);
这是日志:
15:55:54,498 INFO TLDImporter:38 - Opening environment in /home/panayk/Desktop/panag_3.
15:55:54,779 INFO TLDImporter:50 - Opening database in /home/panayk/Desktop/panag_3/panag_3.tld.
这是一个异常(exception):
com.sleepycat.je.DatabaseNotFoundException: (JE 4.1.10) Database /home/panayk/Desktop/panag_3/panag_3.tld not found.
at com.sleepycat.je.Environment.setupDatabase(Environment.java:790)
at com.sleepycat.je.Environment.openDatabase(Environment.java:536)
at gr.panayk.vinyls.importer.TLDImporter.<init>(TLDImporter.java:51)
at gr.panayk.vinyls.persistence.HibernateEntityRegistry.initialize(HibernateEntityRegistry.java:36)
... 60 more
怎么了?该文件显然存在。
最佳答案
/* No database. Create if we're allowed to. */
if (dbConfig.getAllowCreate()) {
/*
* We're going to have to do some writing. Switch to a
* writable locker if we don't already have one. Note
* that the existing locker does not hold the handle lock
* we need, since the database was not found; therefore it
* is OK to call operationEnd on the existing locker.
*/
if (!isWritableLocker) {
locker.operationEnd(OperationStatus.SUCCESS);
locker = LockerFactory.getWritableLocker
(this,
txn,
dbConfig.getTransactional(),
true, // retainNonTxnLocks
autoTxnIsReplicated,
null);
isWritableLocker = true;
}
newDb.initNew(this, locker, databaseName, dbConfig);
} else {
/* We aren't allowed to create this database. */
throw new DatabaseNotFoundException("Database " +
databaseName +
" not found.");
}
你已经设置
final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(false);
setAllowCreate 为 false。通过查看代码,这似乎是问题所在。
关于java - com.sleepycat.je.DatabaseNotFoundException 找不到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6967422/
我有数据库/home/panayk/Desktop/panag_3/panag_3.tld: $ db_verify /home/panayk/Desktop/panag_3/panag_3.tld
我是一名优秀的程序员,十分优秀!