Skip to content

Commit

Permalink
feat(database): 优化数据库连接异常处理
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Sep 6, 2024
1 parent 2b5e222 commit 0e193ed
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Connection getConnection() throws SQLException {
);
return this.connection;
} catch (ClassNotFoundException | SQLException e) {
throw new SQLException("无法建立数据库连接", e);
throw new SQLException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.bukkit.plugin.java.JavaPlugin;

public class SQLite extends SQL {
private Connection connection;
private final Logger logger;

public SQLite(JavaPlugin javaPlugin) {
super(javaPlugin);
this.logger = javaPlugin.getLogger();
}

@Override
Expand All @@ -25,7 +21,6 @@ public Connection getConnection() {
}
return connection;
} catch (SQLException e) {
logger.log(Level.SEVERE, "获取数据库连接失败", e);
return null;
}
}
Expand All @@ -36,8 +31,7 @@ private Connection createConnection() throws SQLException {
Class.forName("org.sqlite.JDBC");
return DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/accounts.db");
} catch (ClassNotFoundException e) {
logger.log(Level.SEVERE, "未找到 SQLite JDBC 驱动", e);
throw new SQLException("未找到 SQLite JDBC 驱动", e);
throw new SQLException(e);
}
}
}

0 comments on commit 0e193ed

Please sign in to comment.