@@ -49,17 +49,30 @@ public class DemoSQLExecutor extends AbstractSQLExecutor {
4949
5050 static {
5151 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 驱动!>>>>>>>>>>>>>>>>>>>>>" );
5455 } catch (ClassNotFoundException e ) {
56+ Log .e (TAG , "加载 MySQL 8 驱动失败,请检查 pom.xml 中 mysql-connector-java 版本是否存在以及可用 !!!" );
5557 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+ }
5667 }
5768
5869 try { //加载驱动程序
70+ Log .d (TAG , "尝试加载 PostgresSQL 驱动 <<<<<<<<<<<<<<<<<<<<< " );
5971 Class .forName ("org.postgresql.Driver" );
60- Log .d (TAG , "成功加载 PostgresSQL 驱动!" );
72+ Log .d (TAG , "成功加载 PostgresSQL 驱动!>>>>>>>>>>>>>>>>>>>>> " );
6173 } catch (ClassNotFoundException e ) {
6274 e .printStackTrace ();
75+ Log .e (TAG , "加载 PostgresSQL 驱动失败,请检查 libs 目录中 postgresql.jar 版本是否存在以及可用 !!!" );
6376 }
6477 }
6578
@@ -95,8 +108,23 @@ public PreparedStatement getStatement(@NotNull SQLConfig config) throws Exceptio
95108 connection = DriverManager .getConnection (config .getDBUri (), config .getDBAccount (), config .getDBPassword ());
96109 }
97110 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+ }
100128 }
101129 connectionMap .put (config .getDatabase (), connection );
102130 }
0 commit comments