sqlite_busy数据库文件已锁定

发布于 2025-01-28 21:37:21 字数 1200 浏览 2 评论 0原文

我正在获取错误[sqlite_busy]数据库文件已锁定(数据库已锁定),即使我关闭了连接和语句。不确定还有什么尝试。

 public void getTeams() throws SQLException {
    Connection c = DriverManager.getConnection("jdbc:sqlite:leagueDatabase.db");
    Statement teamStmt = c.createStatement();
    ResultSet teamData = teamStmt.executeQuery("SELECT * FROM TEAMS");

    while (teamData.next()) {
        teams.add(new Team(teamData.getString("city"), teamData.getString("name")));
    }
    teamData.close();
    teamStmt.close();
    c.close();

    Connection c2 = DriverManager.getConnection("jdbc:sqlite:leagueDatabase.db");
    Statement teamStatsStmt = c2.createStatement();
    ResultSet teamStatsData = teamStatsStmt.executeQuery("SELECT * FROM TEAM_STATS");

    for (int i = 0; i < teams.size(); i++) {
        for (int j = 0; j < players.size(); j++) {
            if (players.get(j).getTeam().equalsIgnoreCase(teams.get(i).getName()))
                teams.get(i).addPlayer(players.get(j));
        }
        teams.get(i).setStats(new TeamStats(teamStatsData.getInt("wins"), teamStatsData.getInt("losses"), (int) Math.round(teams.get(i).calcTeamRating()), SEASON, teams.get(i).getName()));
    }
}

I'm getting the error [SQLITE_BUSY] The database file is locked (database is locked), even though I close my connection and the statements. Not sure what else to try.

 public void getTeams() throws SQLException {
    Connection c = DriverManager.getConnection("jdbc:sqlite:leagueDatabase.db");
    Statement teamStmt = c.createStatement();
    ResultSet teamData = teamStmt.executeQuery("SELECT * FROM TEAMS");

    while (teamData.next()) {
        teams.add(new Team(teamData.getString("city"), teamData.getString("name")));
    }
    teamData.close();
    teamStmt.close();
    c.close();

    Connection c2 = DriverManager.getConnection("jdbc:sqlite:leagueDatabase.db");
    Statement teamStatsStmt = c2.createStatement();
    ResultSet teamStatsData = teamStatsStmt.executeQuery("SELECT * FROM TEAM_STATS");

    for (int i = 0; i < teams.size(); i++) {
        for (int j = 0; j < players.size(); j++) {
            if (players.get(j).getTeam().equalsIgnoreCase(teams.get(i).getName()))
                teams.get(i).addPlayer(players.get(j));
        }
        teams.get(i).setStats(new TeamStats(teamStatsData.getInt("wins"), teamStatsData.getInt("losses"), (int) Math.round(teams.get(i).calcTeamRating()), SEASON, teams.get(i).getName()));
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2025-02-04 21:37:21

您正在关闭第一个连接(C) - 但不是第二个连接(C2)。

您有理由创建两个连接吗?为什么不简单地在第一个连接上创建两个语句,然后在第二个语句之后关闭第一个连接(C)呢?那么您可以完全避免第二个连接(以及您没有关闭的事实可能是您错误的原因)

You are closing the first connection (c) - but not the second connection (c2).

Is there a reason you're creating two connections? Why not simply create both statements on the first connection, then close the first connection (c) after the second statement? Then you could avoid the second connection entirely (and the fact that you're not closing it is likely to be the cause of your error)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文