java hsqldb :连接到文件 db 时获取数据库锁
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16167885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
hsqldb : Database lock acquisition when connecting to a file db
提问by monika
I am trying to connect to a hsqldb (using version 2.2.9).
我正在尝试连接到 hsqldb(使用版本 2.2.9)。
I created one using the following:
我使用以下方法创建了一个:
java -cp hsqldb-2.2.9.jar org/hsqldb/util/DatabaseManagerSwing
When trying to connect to the db thru my ui I'm getting the following exception:
尝试通过我的 ui 连接到数据库时,出现以下异常:
Exception occured : java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@76e90d02[file =/rhel5pdi/home/mgnyp/workspace/src/Project/webapp/WEB-INF/lib/testDataBase.lck, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2013-04-23 10:35:22 heartbeat - read: -8403 ms.
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
I presumed the db is locked because the DatabaseManagerSwing established a connection before my ui did, so I closed that one. This caused the following exception:
我假设数据库被锁定是因为 DatabaseManagerSwing 在我的 ui 之前建立了一个连接,所以我关闭了那个。这导致了以下异常:
Exception occured : java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@76e90d02[file =/rhel5pdi/home/mgnyp/workspace/src/PmtMetricsUI2/webapp/WEB-INF/lib/testDataBase.lck, exists=false, locked=false, valid=false, ] method: openRAF reason: java.io.FileNotFoundException: /rhel5pdi/home/mgnyp/workspace/src/Project/webapp/WEB-INF/lib/testDataBase.lck (Permission denied)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
I'm using spring mvc and c3p0. Connection details (absolute path to the db provided):
我正在使用 spring mvc 和 c3p0。连接详细信息(提供的数据库的绝对路径):
Connection con = DriverManager.getConnection("jdbc:hsqldb:file:/home/mgnyp/workspace/src/Project/webapp/WEB-INF/lib/testDataBase", "SA", "");
I've tried this approach, unsuccessful unfortunately: Database lock acquisition failure and hsqldb
我已经尝试过这种方法,不幸的是没有成功: Database lock purchase failure and hsqldb
I also looked up the docs at hsql.org
我还查找了 hsql.org 上的文档
Apologies if the issue is obvious, I've never used hsql before.
如果问题很明显,我很抱歉,我以前从未使用过 hsql。
I would appreciate any help or hints.
我将不胜感激任何帮助或提示。
Thank you.
谢谢你。
回答by Jason D
I was able to disable the lock file by including ;readonly=true as a property on the additional connection string. Otherwise I've found that the lock is always held for a file database. A sample connection string that worked for me was jdbc:hsqldb:file:my/file/location;readonly=true
我能够通过将 ;readonly=true 作为附加连接字符串的属性来禁用锁定文件。否则我发现锁总是为文件数据库持有的。对我有用的示例连接字符串是 jdbc:hsqldb:file:my/file/location;readonly=true
回答by subbu s
I had the same problem. just deleted the .lck (lock ) file and reconnected. Now it works fine.
我有同样的问题。刚刚删除了 .lck(锁定)文件并重新连接。现在它工作正常。