@@ -42,7 +42,7 @@ public class DemoSQLExecutor extends AbstractSQLExecutor {
4242 } catch (ClassNotFoundException e ) {
4343 e .printStackTrace ();
4444 }
45-
45+
4646 try { //加载驱动程序
4747 Class .forName ("org.postgresql.Driver" );
4848 Log .d (TAG , "成功加载 PostgresSQL 驱动!" );
@@ -65,6 +65,8 @@ public int executeUpdate(@NotNull SQLConfig config) throws Exception {
6565 }
6666
6767
68+ //TODO 根据不同数据库来分组存 connection 和 statement,例如 Map<database, connection>,
69+ // 解决一次请求中有2个以上不同数据库类型导致后面的查询都用第一个的数据库类型
6870 private Connection connection = null ;
6971 private PreparedStatement statement = null ;
7072 /**
@@ -76,7 +78,6 @@ private PreparedStatement getStatement(@NotNull SQLConfig config) throws Excepti
7678 if (connection == null || connection .isClosed ()) {
7779 Log .i (TAG , "select connection " + (connection == null ? " = null" : ("isClosed = " + connection .isClosed ()))) ;
7880
79-
8081 if (DemoSQLConfig .DATABASE_POSTGRESQL .equalsIgnoreCase (config .getDatabase ())) { //PostgreSQL 不允许 cross-database
8182 connection = DriverManager .getConnection (config .getDBUri () + "/" + config .getSchema (), config .getDBAccount (), config .getDBPassword ());
8283 }
@@ -85,14 +86,14 @@ private PreparedStatement getStatement(@NotNull SQLConfig config) throws Excepti
8586 + config .getDBAccount () + "&password=" + config .getDBPassword ());
8687 }
8788 }
88-
89+
8990 statement = connection .prepareStatement (config .getSQL (config .isPrepared ())); //创建Statement对象
9091 List <Object > valueList = config .isPrepared () ? config .getPreparedValueList () : null ;
91-
92+
9293 if (valueList != null && valueList .isEmpty () == false ) {
93-
94+
9495 for (int i = 0 ; i < valueList .size (); i ++) {
95-
96+
9697 if (DemoSQLConfig .DATABASE_POSTGRESQL .equalsIgnoreCase (config .getDatabase ())) {
9798 statement .setObject (i + 1 , valueList .get (i )); //PostgreSQL JDBC 不支持隐式类型转换 tinyint = varchar 报错
9899 }
0 commit comments