Commit bb68ad6 1 parent 38ddf7f commit bb68ad6 Copy full SHA for bb68ad6
File tree 1 file changed +3
-5
lines changed
src/main/java/cc/baka9/catseedlogin/bukkit/database
1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change @@ -15,24 +15,22 @@ public MySQL(JavaPlugin javaPlugin){
15
15
}
16
16
17
17
@ Override
18
- public Connection getConnection () throws SQLException {
19
-
18
+ public Connection getConnection () throws SQLException {
20
19
if (this .connection != null && !this .connection .isClosed () && this .connection .isValid (10 )) {
21
20
return this .connection ;
22
21
}
23
22
24
23
try {
25
- Class .forName ("com.mysql.jdbc.Driver" );
24
+ Class .forName ("com.mysql.cj. jdbc.Driver" ); // 修改此处加载驱动程序的方式
26
25
this .connection = DriverManager .getConnection (
27
26
"jdbc:mysql://" + Config .MySQL .Host + ":" + Config .MySQL .Port + "/" + Config .MySQL .Database + "?characterEncoding=UTF-8" ,
28
27
Config .MySQL .User , Config .MySQL .Password
29
28
);
30
29
return this .connection ;
31
- } catch (ClassNotFoundException e ) {
30
+ } catch (ClassNotFoundException | SQLException e ) { // 增加SQLException处理
32
31
e .printStackTrace ();
33
32
return null ;
34
33
}
35
-
36
34
}
37
35
38
36
}
You can’t perform that action at this time.
0 commit comments