【问题标题】:java.sql.SQLException: Error opening connectionjava.sql.SQLException:打开连接时出错
【发布时间】:2021-12-31 01:04:41
【问题描述】:

我正在尝试使用 MacBook Apple Silicone M1 连接到 SQLite。 这是我在 IntelliJ 中创建 URL 时建立连接的代码,它正是 SQLite 名称。

这里是代码。

 private static final String SQLite_URL = "jdbc:sqlite:identifier.sqlite";
        Connection conn = null;
        if (DatastoreToggles.isUnderTest) {
            try {
                Class.forName("org.sqlite.JDBC");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                conn = DriverManager.getConnection(SQLite_URL_TEST);

                System.out.println("Connection to test SQLite successful");

            }
            catch (SQLException e) {
                System.out.println(e.getMessage());
            }
        }
        else {
            try {
                conn = DriverManager.getConnection(SQLite_URL);

                System.out.println("Connection to SQLite successful");

            }
            catch (SQLException e) {
                System.out.println(e.getMessage());
            }
        }

        return conn;
    }

我已经检查过其他有类似问题的人,我确实更新了我的 maven,但问题仍然存在。

  <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.25.2</version>
        </dependency>

IntelliJ 内部的测试连接通过但无法连接到我的代码。

这是控制台的报告

【问题讨论】:

    标签: java spring-boot sqlite


    【解决方案1】:

    在 sqlite-jdbc 的 3.32.3.3 中发布了 M1 支持,但您使用的是 3.25.2。所以,请更新你的依赖

    【讨论】:

    • 更改依赖,它正在工作,谢谢!
    • 请将答案标记为“已接受”,以便其他用户轻松看到它的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多