我正在使用orientdb。样品是很简单的:为什么在关闭连接时抛出异常?
package models;
import java.util.List;
import com.orientechnologies.orient.core.db.object.ODatabaseObjectPool;
import com.orientechnologies.orient.core.db.object.ODatabaseObjectTx;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
public class User {
public String name;
public static void main(String[] args) {
String uri = "local:c:\\orientdb";
ODatabaseObjectTx db = ODatabaseObjectPool.global().acquire(uri, "admin", "admin");
db.getEntityManager().registerEntityClass(User.class);
User user = new User();
user.name = "aaa";
db.save(user);
List<?> list = db.query(new OSQLSynchQuery<Long>("select count(*) from User"));
System.out.println(list);
db.commit();
db.close(); // ****** throws exception
}
}
但最后一行db.close()
将抛出一个异常:
Exception in thread "main" com.orientechnologies.common.concur.lock.OLockException: Can't release a database URL not acquired before. URL: c:\orientdb
at com.orientechnologies.orient.core.db.ODatabasePoolAbstract.release(ODatabasePoolAbstract.java:81)
at com.orientechnologies.orient.core.db.ODatabasePoolBase.release(ODatabasePoolBase.java:43)
at com.orientechnologies.orient.core.db.object.ODatabaseObjectTxPooled.close(ODatabaseObjectTxPooled.java:81)
at models.User.main(User.java:26)
哪里错了?
db.isClosed()在commit()之后返回什么? – MeBigFatGuy 2011-05-06 03:59:51
@MeBigFatGuy,我发现它是一个orientdb的bug。看到我的回答 – Freewind 2011-05-06 06:34:25
当我在java中使用数据库时遇到了同样的情况,并且我得到了异常,因为有可能连接没有建立。所以,如果没有入门,连接就无法关闭,因此是一个例外。我想在使用OrientDB中的windows路径建立连接时会出现错误,因为我发现Freewind的评论。 – 2011-05-06 07:03:33