HsqlException:数据库锁获取失败:原因:java.io.FileNotFoundException:/data/explorecalifornia.lck(没有这样的文件或目录)

问题描述 投票:0回答:1

我正在尝试使用 Java 连接到 HSQL。 我正在使用 JDBC 和 hibernate 的教程。 这是琳达教程。 无论如何,这是下面的代码:

package com.lynda.javatraining.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Main {

    private static final String USERNAME = "dbuser";
    private static final String PASSWORD = "dbpassword";
    private static final String CONN_STRING =
            "jdbc:hsqldb://data/explorecalifornia";
    
    public static void main(String[] args) throws SQLException {
        
        //Class.forName("com.mysql.jdbc.Driver");
        
        Connection conn = null;
        System.out.println("A");
        System.out.println(conn == null);
        System.out.println(CONN_STRING);
        try {
            System.out.println("B1");
            conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
            System.out.println("B1-2");
            System.out.println("Connected!");
        } catch (SQLException e) {
            System.out.println("B2");
            System.err.println(e);
        } finally {
            System.out.println("B3");
            if (conn != null) {
                conn.close();
            }
        }
        System.out.println("C");
        
    }

}

这是我收到的错误:

A
true
jdbc:hsqldb://data/explorecalifornia
B1
2014-06-27T15:26:27.430-0400  SEVERE  could not reopen database
org.hsqldb.HsqlException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@76d682a[file =/data/explorecalifornia.lck, exists=false, locked=false, valid=false, ] method: openRAF reason: java.io.FileNotFoundException: /data/explorecalifornia.lck (No such file or directory)
    at org.hsqldb.error.Error.error(Unknown Source)
    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)
    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:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at com.lynda.javatraining.db.Main.main(Main.java:24)

B2
java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@76d682a[file =/data/explorecalifornia.lck, exists=false, locked=false, valid=false, ] method: openRAF reason: java.io.FileNotFoundException: /data/explorecalifornia.lck (No such file or directory)
B3
C

谁能告诉我我做错了什么?

java hibernate jdbc hsqldb
1个回答
1
投票

数据库具有阻止通信的锁定文件

explorecalifornia.lck
。您应该删除锁定文件并重新启动数据库。当您意外关闭数据库或系统时,这种情况可能会时常发生。

查看命令行中用于调用 shutdown 的命令语法。还有一个选项如何在 Java 中关闭服务器

© www.soinside.com 2019 - 2024. All rights reserved.