Java 为什么在关闭连接时抛出异常?
我想用它。示例非常简单:Java 为什么在关闭连接时抛出异常?,java,orientdb,Java,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.OSQ
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
}
}
哪里错了?最后,我发现它是Orientdb的一个bug。它无法正确处理windows路径,并且无法提供良好的错误消息 如果我使用
local:c:/orientdb
而不是local:c:\orientdb
,一切都很好
我已经向orientdb团队报告了这个问题。最后,我发现它是orientdb的一个bug。它无法正确处理windows路径,并且无法提供良好的错误消息 如果我使用
local:c:/orientdb
而不是local:c:\orientdb
,一切都很好
我已经向orientdb团队报告了这一点。提交()后db.isClosed()返回什么?@MeBigFatGuy,我发现这是orientdb的一个bug。看到我的回答了吗?我在用java使用数据库时遇到了同样的问题,我得到了一个异常,因为有可能连连接都没有建立起来。因此,如果不启动连接,则无法关闭连接,因此出现异常。当我在OrientDB中找到Freewind的注释时,我猜在使用windows路径建立连接时一定发生了错误。在commit()之后db.isClosed()返回什么?@MeBigFatGuy,我发现这是OrientDB的一个bug。看到我的回答了吗?我在用java使用数据库时遇到了同样的问题,我得到了一个异常,因为有可能连连接都没有建立起来。因此,如果不启动连接,则无法关闭连接,因此出现异常。我想在OrientDB中使用windows路径建立连接时一定会出错,因为我找到了Freewind的评论。感谢您的确认!刚刚遇到了相同的错误。感谢您的确认!只是遇到了同样的错误。
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)