Commit 4b40a33 1 parent 9be2da1 commit 4b40a33 Copy full SHA for 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 number Diff line number Diff line change 1
1
package cc .baka9 .catseedlogin .bukkit .database ;
2
2
3
3
import org .bukkit .plugin .java .JavaPlugin ;
4
-
5
4
import java .sql .Connection ;
6
5
import java .sql .DriverManager ;
7
6
import java .sql .SQLException ;
8
7
9
8
public class SQLite extends SQL {
10
9
private Connection connection ;
11
10
12
- public SQLite (JavaPlugin javaPlugin ) {
13
- super (javaPlugin );
11
+ public SQLite (JavaPlugin plugin ) {
12
+ super (plugin );
14
13
}
15
14
16
-
17
- @ Override
18
- public Connection getConnection () throws SQLException {
19
-
15
+ public Connection getConnection () {
20
16
if (this .connection != null && !this .connection .isClosed ()) {
21
17
return this .connection ;
22
18
}
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 ();
35
32
}
36
- }
37
33
34
+ return this .connection ;
35
+ }
38
36
}
You can’t perform that action at this time.
0 commit comments