sqlite_busy数据库文件已锁定
我正在获取错误[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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在关闭第一个连接(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)