没有连接到HSQLDB数据库

时间:2019-12-12 14:57:53

标签: database-connection hsqldb

我已经存在数据库。当我测试连接时,会出现此异常

java.sql.SQLInvalidAuthorizationSpecException: invalid authorization specification: SA
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.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(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at libraryapp.AppConnect.getConnection(AppConnect.java:17)
at libraryapp.TestAppConnection.main(TestAppConnection.java:7)
Caused by: org.hsqldb.HsqlException: invalid authorization specification: SA
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.rights.User.checkPassword(Unknown Source)
at org.hsqldb.rights.UserManager.getUser(Unknown Source)
at org.hsqldb.Database.connect(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source)

我的联系班

public class AppConnect {
    private static final String url ="jdbc:hsqldb:file:src/main/resources/db/library";
    private static final String driver ="org.hsqldb.jdbcDriver";
    private static final String user = "SA";
    private static final String password = " ";

    public Connection getConnection() {
        Connection connection = null;
        try {
            Class.forName(driver);
            connection = DriverManager.getConnection(url, user, password);
            connection.setAutoCommit(true);
            System.out.println("Good connection");
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
            System.out.println("Failed to establish the connection :(");
        }
        return connection;
    }
}

在pom.xml中,我有这个

<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>2.5.0</version>
</dependency>

如果我将路径更改为不存在的数据库,则会创建并连接

1 个答案:

答案 0 :(得分:0)

该错误表示您的连接URL找到了数据库,但用户名和密码的组合不正确。

您使用的密码是一个空格,但是数据库的默认密码是空字符串。尝试将其更改为:

  private static final String password = "";

如果这不起作用,则需要找出创建数据库时最初用作用户名和密码的内容。