Database lock acquisition failure and hsqldb

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.

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.

HyperSQL Database Engine (HSQLDB) / Discussion / Help: HSQL , HsqlException: Database lock acquisition failure: lockFile: org.hsqldb.persist.​LockFile@4facc966 method: checkHeartbeat read: 2011-03-12  We are aware when the property hsqldb.cache_version=1.7.0 is present in the properties file, 2.3.4 works fine and sets the database name correctly and Lock Acquisition problems are gone. However hsqldb always parses and removes the entry, is there a configuration or a call in hsqldb which forces it to not delete

If you have any other client running that connects to your db you need to close that.

User - Database lock acquisition failure, Database lock acquisition failure. Folks, I didn't have as much luck debugging this one. I'm surprised that the transaction is requesting a new  Re: Database lock acquisition failure Which version of HSQLDB is this? This can happen if the shutdown=true property is used on the connections to the database, or the application shuts down the database deliberately.

I face this error because I wanted to view a currently opened database in another client like IntelliJ database while the server is using the same db

so to make hsql db able to be connected to multiple clients, use

hsqldb.lock_file=false

so the connection url will be like

jdbc:hsqldb:file:./db/myDbInFile;hsqldb.lock_file=false

Explanation: Database lock acquisition failure error, Many users run into such error after they upgrade Openfire: java.sql.​SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist. The database lock means you have already opened the database froma Java process. You are now trying to open it from a different Java process, which fails because it is not allowed. If you would like to refer to this comment somewhere else in this project, copy and paste the following link:

Whatever way you have tried is correct.

You don't have to start the HSQLDB Server using seperate java command, below line is not required, as it will lock the database. Prevent other process from starting and locking db.

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

just run the jdbc program

java -cp hsqldb.jar  HSQLAccess 

below line

jdbc:hsqldb:file:db/sjdb

will start the database and will give result.

in this way you don't have to start the server seperately, just have to run the program, which will start and stop HSQLDB for you.

import java.sql.*;

public class HSQLAccess {

    public static void main(String args[]) throws Exception
    {
        Connection con = null;
        try
        {
            Class.forName("org.hsqldb.jdbcDriver");         
            con = DriverManager.getConnection("jdbc:hsqldb:file:db/sjdb", "sa","");    

            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM CMDS_WO_MASTER");
            while(rs.next())
            {
                System.out.println(rs.getString(1));
            }

            con.close();

        }
        catch(Exception ex )
        {
            ex.printStackTrace();
        }
        finally
        {
            if(con!=null)
            {
                 con.close();
            }
        }
    }
}

[#LENS-244] HSQL Database lock acquisition failure when , Suppose database access from B when same time when accessing from C shows error --->>Database lock acquisition failure: lockFile:  Connecting to Sample Database. Database JDBC Connection for Data Adapter: java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist

on my Mac, the port for Connector on HTTP changed from 8080 to 8443 on server.xml. and that is what was giving me this error: both HTTP and HTTPS schema were using the same port

Putting HSQLDB in server mode with multi-user then Database lock , Error.error(Unknown Source) [4:44:16 PM] INFO: Caused by: org.hsqldb.​HsqlException: Database lock acquisition failure: lockFile  You can access HSQLDB database that has lock by: 1- updating my-db-name.properties file and add: hsqldb.lock_file=false 2- or removing my-db-name.lck file. 3- or connect to the database using pass the properties as parameters:

java.sql.SQLException: Database lock acquisition failure , BasicResourcePool$AcquireTask@1dbb12b -- Acquisition Attempt Failed!!! lock file [/opt/liferay-portal-5.2.3/data/hsql/lportal.lck] is presumably locked by  Database Lock Acquisition Failure Hello, We run hsqldb in a web environment, with Servlets under Jboss. Our stable version uses 2.3.2 but we encountered issues with query aggregates which were solved with a 2.3.4 upgrade.

Exception when locks cannot be deleted (for example untitled1.lck , Exception when locks cannot be deleted (for example untitled1 Exception when locks cannot be hsqldb.HsqlException: Database lock acquisition failure: lockFile

hsql database lock?! - Forums,