Skip to content

Commit

Permalink
feat(database): 修改SQLite数据库连接方式
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Jun 8, 2024
1 parent bb68ad6 commit 5b3275a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"java.jdt.ls.java.home": "D:\\Program Files\\Java\\jdk-21",
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.runtimes": [
{
"name": "JavaSE-21",
"path": "D:\\Program Files\\Java\\jdk-21",
"default": true
},
],
"java.configuration.updateBuildConfiguration": "interactive"
}
1 change: 0 additions & 1 deletion src/main/java/cc/baka9/catseedlogin/bukkit/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.io.*;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/cc/baka9/catseedlogin/bukkit/database/SQLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ public SQLite(JavaPlugin javaPlugin){


@Override
public Connection getConnection() throws SQLException{

public Connection getConnection() {
try {
if (this.connection != null && !this.connection.isClosed()) {
return this.connection;
}
if (plugin.getDataFolder().exists()) {
try {
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/accounts.db");
return this.connection;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
return null;
}
} else {
final boolean mkdir = plugin.getDataFolder().mkdir();
return this.getConnection();

if (!plugin.getDataFolder().exists()) {
plugin.getDataFolder().mkdir();
}

Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + "/accounts.db");

return this.connection;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
return null;
}
}

}

0 comments on commit 5b3275a

Please sign in to comment.