Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database lock acquisition failure and hsqldb

Tags:

I was trying to connect to a hsql db. I created one by running from C:\myhsql:

java -cp .;C:\hsql\lib\hsqldb.jar org.hsqldb.Server -database.0 file:db\mydb -dbname.0 MYDB 

This created mydb in a directory called db. This folder now has a .lck,tmp,script,properties files with name mydb, and similar files with name MYDB in current folder .

In java code I tried

Class.forName("org.hsqldb.jdbcDriver"); connection = DriverManager.getConnection("jdbc:hsqldb:file:db/sjdb", "SA", ""); 

When I run the program, I am getting this error:

java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@f3811c1a[file =C:\myhsql\db\mydb.lc k, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2010-10-19 12:46:09 heartbeat - read: -6750 ms. ... 

Here is the stacktrace:

java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@f3811c1a[file =C:\myhsql\db\sjdb.lc k, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2010-10-19 12:46:09 heartbeat - read: -6750 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(Unknown Source)         at java.sql.DriverManager.getConnection(Unknown Source)         at ConnectHSQLDB.main(ConnectHSQLDB.java:20) Caused by: org.hsqldb.HsqlException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@f3811c1a[file =C:\myhsql\db\sjdb.lck, exists=true, locked=false, valid=false, ] method: checkHeartbeat read: 2010-10-19 12:46:09 heartbeat - read: -6750 ms.         at org.hsqldb.error.Error.error(Unknown Source)         at org.hsqldb.persist.LockFile.newLockFileLock(Unknown Source)         at org.hsqldb.persist.Logger.acquireLock(Unknown Source)         at org.hsqldb.persist.Logger.openPersistence(Unknown Source)         at org.hsqldb.Database.reopen(Unknown Source)         at org.hsqldb.Database.open(Unknown Source)         at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)         at org.hsqldb.DatabaseManager.newSession(Unknown Source)         ... 6 more java.lang.NullPointerException         at ConnectHSQLDB.main(ConnectHSQLDB.java:32) 

Can somebody tell me what I am doing wrong? I can connect to the db using SwingDBManager and can insert, delete, and select records in the db. I was not running DBManager when I tried the java code. Still the lock problem happens.

like image 708
markjason72 Avatar asked Oct 19 '10 13:10

markjason72


People also ask

What is HSQLDB in-memory database?

HSQLDB (HyperSQL Database) HSQLDB is an open source project, also written in Java, representing a relational database. It follows the SQL and JDBC standards and supports SQL features such as stored procedures and triggers. It can be used in the in-memory mode, or it can be configured to use disk storage.

What is HSQLDB used for?

HSQLDB is available under a BSD license. It is used as a database and persistence engine in many open source software projects, such as descendants of OpenOffice.org Base (i.e., Apache OpenOffice Base, LibreOffice Base, etc.), and the Jitsi VoIP and video-conference client since version 2.6.

What is HSQLDB embedded?

HSQLDB (HyperSQL DataBase) is the leading SQL relational database system written in Java. It offers a small, fast multithreaded and transactional database engine with in-memory and disk-based tables and supports embedded and server modes. It includes a powerful command line SQL tool and simple GUI query tools.

Who uses HSQLDB?

5 companies reportedly use HSQLDB in their tech stacks, including Swingvy, picturesafe media/data/bank GmbH, and Sakai.


1 Answers

The first command starts a server. This server locks the database files so that "others" cannot modify them. You should use "-dbname.0 mydb" instead of "MYDB" as it should be in lowercase.

Your Java connection URL to connect to the database is wrong. You should use "jdbc:hsqldb:hsql://localhost/mydb" as the connection string. While the database files are locked by the server, you can access the database server but you cannot access the database "in-process" with a file: URL.

like image 148
fredt Avatar answered Oct 13 '22 21:10

fredt