title: Database lock acquisition failure and hsqldb
body: <p>I was trying to connect to a hsql db. I created one by running from C:\myhsql:</p>
  
  <pre><code>java -cp .;C:\hsql\lib\hsqldb.jar org.hsqldb.Server -database.0 file:db\mydb -dbname.0 MYDB
  </code></pre>
  
  <p>This created <code>mydb</code> in a directory called <code>db</code>. This folder now has a .lck,tmp,script,properties files with name mydb, and similar files with name MYDB in current folder .</p>
  
  <p>In java code I tried</p>
  
  <pre><code>Class.forName("org.hsqldb.jdbcDriver");
  connection = DriverManager.getConnection("jdbc:hsqldb:file:db/sjdb", "SA", "");
  </code></pre>
  
  <p>When I run the program, I am getting this error:</p>
  
  <pre><code>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.
  ...
  </code></pre>
  
  <p>Here is the stacktrace:</p>
  
  <pre><code>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.&lt;init&gt;(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)
  </code></pre>
  
  <p>Can somebody tell me what I am doing wrong? I can connect to the db using SwingDBManager  and can <code>insert</code>, <code>delete</code>, and <code>select</code> records in the db. I was not running DBManager when I tried the java code. Still the lock problem happens.</p>