SQLITE_BUSY 数据库文件被锁定

SQLITE_BUSY The database file is locked

我收到错误 [SQLITE_BUSY] The database file is locked (database is locked),即使我关闭了连接和语句。不确定还能尝试什么。

 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()));
    }
}

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

您创建两个连接是否有原因?为什么不简单地在第一个连接上创建两个语句,然后在第二个语句之后关闭第一个连接 (c)?然后你可以完全避免第二个连接(你没有关闭它的事实很可能是你错误的原因)