我尝试使用java连接到HSQL。我使用教程来使用JDBC和hibernate。这是lynda教程。无论如何,这里的代码如下:
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
谁能告诉我我做错了什么?谢谢。
答案 0 :(得分:1)
数据库具有阻止通信的锁定文件explorecalifornia.lck
。您应该删除锁定文件并重新启动数据库。当您意外关闭数据库或系统时,可能会发生这种情况。
请参阅命令行中用于调用shutdown的命令的语法。还有一个选项how to shutdown server in Java。