Skip to content

Commit 5b3275a

Browse files
committed
feat(database): 修改SQLite数据库连接方式
1 parent bb68ad6 commit 5b3275a

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

.vscode/settings.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"java.jdt.ls.java.home": "D:\\Program Files\\Java\\jdk-21",
3+
"java.compile.nullAnalysis.mode": "automatic",
4+
"java.configuration.runtimes": [
5+
{
6+
"name": "JavaSE-21",
7+
"path": "D:\\Program Files\\Java\\jdk-21",
8+
"default": true
9+
},
10+
],
11+
"java.configuration.updateBuildConfiguration": "interactive"
12+
}

src/main/java/cc/baka9/catseedlogin/bukkit/Config.java

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import java.io.*;
1212
import java.lang.reflect.Field;
13-
import java.nio.charset.Charset;
1413
import java.nio.charset.StandardCharsets;
1514
import java.nio.file.Files;
1615
import java.util.*;

src/main/java/cc/baka9/catseedlogin/bukkit/database/SQLite.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ public SQLite(JavaPlugin javaPlugin){
1515

1616

1717
@Override
18-
public Connection getConnection() throws SQLException{
19-
18+
public Connection getConnection() {
19+
try {
2020
if (this.connection != null && !this.connection.isClosed()) {
2121
return this.connection;
2222
}
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();
23+
24+
if (!plugin.getDataFolder().exists()) {
25+
plugin.getDataFolder().mkdir();
3526
}
27+
28+
Class.forName("org.sqlite.JDBC");
29+
this.connection = DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/accounts.db");
30+
31+
return this.connection;
32+
} catch (ClassNotFoundException | SQLException e) {
33+
e.printStackTrace();
34+
return null;
3635
}
36+
}
3737

3838
}

0 commit comments

Comments
 (0)