@@ -49,17 +49,30 @@ public class DemoSQLExecutor extends AbstractSQLExecutor {
49
49
50
50
static {
51
51
try { //加载驱动程序
52
- Class .forName ("com.mysql.jdbc.Driver" );
53
- Log .d (TAG , "成功加载 MySQL 驱动!" );
52
+ Log .d (TAG , "尝试加载 MySQL 8 驱动 <<<<<<<<<<<<<<<<<<<<< " );
53
+ Class .forName ("com.mysql.cj.jdbc.Driver" );
54
+ Log .d (TAG , "成功加载 MySQL 8 驱动!>>>>>>>>>>>>>>>>>>>>>" );
54
55
} catch (ClassNotFoundException e ) {
56
+ Log .e (TAG , "加载 MySQL 8 驱动失败,请检查 pom.xml 中 mysql-connector-java 版本是否存在以及可用 !!!" );
55
57
e .printStackTrace ();
58
+
59
+ try { //加载驱动程序
60
+ Log .d (TAG , "尝试加载 MySQL 7 及以下版本的 驱动 <<<<<<<<<<<<<<<<<<<<< " );
61
+ Class .forName ("com.mysql.jdbc.Driver" );
62
+ Log .d (TAG , "成功加载 MySQL 7 及以下版本的 驱动!>>>>>>>>>>>>>>>>>>>>> " );
63
+ } catch (ClassNotFoundException e2 ) {
64
+ Log .e (TAG , "加载 MySQL 7 及以下版本的 驱动失败,请检查 pom.xml 中 mysql-connector-java 版本是否存在以及可用 !!!" );
65
+ e2 .printStackTrace ();
66
+ }
56
67
}
57
68
58
69
try { //加载驱动程序
70
+ Log .d (TAG , "尝试加载 PostgresSQL 驱动 <<<<<<<<<<<<<<<<<<<<< " );
59
71
Class .forName ("org.postgresql.Driver" );
60
- Log .d (TAG , "成功加载 PostgresSQL 驱动!" );
72
+ Log .d (TAG , "成功加载 PostgresSQL 驱动!>>>>>>>>>>>>>>>>>>>>> " );
61
73
} catch (ClassNotFoundException e ) {
62
74
e .printStackTrace ();
75
+ Log .e (TAG , "加载 PostgresSQL 驱动失败,请检查 libs 目录中 postgresql.jar 版本是否存在以及可用 !!!" );
63
76
}
64
77
}
65
78
@@ -95,8 +108,23 @@ public PreparedStatement getStatement(@NotNull SQLConfig config) throws Exceptio
95
108
connection = DriverManager .getConnection (config .getDBUri (), config .getDBAccount (), config .getDBPassword ());
96
109
}
97
110
else {
98
- connection = DriverManager .getConnection (config .getDBUri () + "?useUnicode=true&characterEncoding=UTF-8&user="
99
- + config .getDBAccount () + "&password=" + config .getDBPassword ());
111
+ int v ;
112
+ try {
113
+ String [] vs = config .getDBVersion ().split ("[.]" );
114
+ v = Integer .parseInt (vs [0 ]);
115
+ } catch (Exception e ) {
116
+ v = 1 ;
117
+ Log .e (TAG , "getStatement try { String[] vs = config.getDBVersion().split([.]); ... >> } catch (Exception e) {\n " + e .getMessage ());
118
+ }
119
+
120
+ if (v >= 8 ) {
121
+ connection = DriverManager .getConnection (config .getDBUri () + "?userSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&user="
122
+ + config .getDBAccount () + "&password=" + config .getDBPassword ());
123
+ }
124
+ else {
125
+ connection = DriverManager .getConnection (config .getDBUri () + "?useUnicode=true&characterEncoding=UTF-8&user="
126
+ + config .getDBAccount () + "&password=" + config .getDBPassword ());
127
+ }
100
128
}
101
129
connectionMap .put (config .getDatabase (), connection );
102
130
}
0 commit comments