Skip to content

Commit 4b40a33

Browse files
authored
更新 SQLite.java
1 parent 9be2da1 commit 4b40a33

File tree

1 file changed

+18
-20
lines changed
  • src/main/java/cc/baka9/catseedlogin/bukkit/database

1 file changed

+18
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
package cc.baka9.catseedlogin.bukkit.database;
22

33
import org.bukkit.plugin.java.JavaPlugin;
4-
54
import java.sql.Connection;
65
import java.sql.DriverManager;
76
import java.sql.SQLException;
87

98
public class SQLite extends SQL {
109
private Connection connection;
1110

12-
public SQLite(JavaPlugin javaPlugin){
13-
super(javaPlugin);
11+
public SQLite(JavaPlugin plugin) {
12+
super(plugin);
1413
}
1514

16-
17-
@Override
18-
public Connection getConnection() throws SQLException{
19-
15+
public Connection getConnection() {
2016
if (this.connection != null && !this.connection.isClosed()) {
2117
return this.connection;
2218
}
23-
if (plugin.getDataFolder().exists()) {
24-
try {
25-
Class.forName("org.sqlite.JDBC");
26-
this.connection = DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/accounts.db");
27-
return this.connection;
28-
} catch (ClassNotFoundException | SQLException e) {
29-
e.printStackTrace();
30-
return null;
31-
}
32-
} else {
33-
final boolean mkdir = plugin.getDataFolder().mkdir();
34-
return this.getConnection();
19+
20+
// 确保插件的数据文件夹存在
21+
if (!plugin.getDataFolder().exists()) {
22+
plugin.getDataFolder().mkdir();
23+
}
24+
25+
try {
26+
// 加载SQLite的JDBC驱动
27+
Class.forName("org.sqlite.JDBC");
28+
// 创建数据库连接
29+
this.connection = DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/accounts.db");
30+
} catch (ClassNotFoundException | SQLException e) {
31+
e.printStackTrace();
3532
}
36-
}
3733

34+
return this.connection;
35+
}
3836
}

0 commit comments

Comments
 (0)