Forráskód Böngészése

修改为dm数据源

zyl 11 hónapja
szülő
commit
ce4701a217

+ 6 - 0
pom.xml

@@ -116,6 +116,12 @@
             <version>6.4.0.jre8</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.dm</groupId>
+            <artifactId>DmJdbcDriver18</artifactId>
+            <version>1.8.0</version>
+        </dependency>
+
         <!--pgsql-->
         <dependency>
             <groupId>org.postgresql</groupId>

+ 14 - 14
src/main/java/com/citygis/impl/WSForSqlServiceImpl.java

@@ -53,7 +53,7 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
         response.setContentType("text/html;charset=UTF-8");
         //操作失败处理
         if (!"".equals(ErrorMessage)) {
-            queryResult = "[{\"IsSuc\":\"" + "Fault" + "\",\"Msg\":\"" + ErrorMessage.replaceAll("'"," ").replaceAll("\\\\","\\\\\\\\") + "\",\"AllCount\":\"" + 0 + "\",\"pageIndex\":\"" + 0 + "\",\"CurrCount\":\"1\",\"pkid\":\"\",\"data\":" + "[{}]" + "}]";
+            queryResult = "[{\"IsSuc\":\"" + "Fault" + "\",\"Msg\":\"" + ErrorMessage.replaceAll("'", " ").replaceAll("\\\\", "\\\\\\\\") + "\",\"AllCount\":\"" + 0 + "\",\"pageIndex\":\"" + 0 + "\",\"CurrCount\":\"1\",\"pkid\":\"\",\"data\":" + "[{}]" + "}]";
             String res = "Fault";
             try {
                 res = queryResult.substring(11, 17);
@@ -77,8 +77,8 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
                 res = AnalyseSql.substring(0, 299);
             }
             //日志记录
-            String sqlStr = " insert into " + tableName_Log + " (token,操作,传输数据,操作表,备注,result,sqlstr,ip) "
-                    + "values ('" + token + "','" + operation + "','" + variable + "','" + tablename + "','" + queryResult + "','" + res + "','" + AnalyseSql + "','" + ip + "')";
+            String sqlStr = " INSERT INTO MIDDB.\" " + tableName_Log + "\" (TOKEN,操作,传输数据,操作表,备注,RESULT,SQLSTR,IP) "
+                    + "VALUES ('" + token + "','" + operation + "','" + variable + "','" + tablename + "','" + queryResult + "','" + res + "','" + AnalyseSql + "','" + ip + "')";
             String Result_RZ = dbUtilSqlServer.UpadteDataBase(sqlStr);
             //日志插入失败 再次插入
             try {
@@ -115,13 +115,13 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
             }
             variable = variable.replaceAll(" ", "+");
             Base64 base64 = new Base64();
-            variable = new String(base64.decode(variable), "utf-8").replaceAll("'","''");  //接口传参base64解析
+            variable = new String(base64.decode(variable), "utf-8").replaceAll("'", "''");  //接口传参base64解析
             JSONObject jsonObject = new JSONObject(); //字符串转json
             JSONObject jsonObjData = JSON.parseObject(variable);
             token = jsonObjData.getString("token");
             operation = jsonObjData.getString("operation").toLowerCase();
             tablename = jsonObjData.getString("tablename");
-            if (tablename.toLowerCase().contains("select") || tablename.toLowerCase().contains("insert") || tablename.toLowerCase().contains("update")
+            if (tablename.toLowerCase().contains("select") || tablename.toLowerCase().contains("insert") || tablename.toLowerCase().contains("update ")
                     || tablename.toLowerCase().contains("delete") || tablename.toLowerCase().contains("create") || tablename.toLowerCase().contains("drop")
                     || tablename.toLowerCase().contains("alter")) {
                 ErrorMessage = "SQL注入非法请求!!!";
@@ -153,14 +153,14 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
                         String field2 = primary.split(",")[n].toLowerCase();
                         if (field2.toLowerCase().contains("select") || field2.toLowerCase().contains("insert") || field2.toLowerCase().contains("update")
                                 || field2.toLowerCase().contains("delete") || field2.toLowerCase().contains("create") || field2.toLowerCase().contains("drop")
-                                || field2.toLowerCase().contains("alter")) {
+                                || field2.toLowerCase().contains("alter ")) {
                             ErrorMessage = "SQL注入非法请求!!!";
                             return "";
                         }
                         String value2 = where.split(",")[n].toLowerCase();
                         if (value2.toLowerCase().contains("select") || value2.toLowerCase().contains("insert") || value2.toLowerCase().contains("update")
                                 || value2.toLowerCase().contains("delete") || value2.toLowerCase().contains("create") || value2.toLowerCase().contains("drop")
-                                || value2.toLowerCase().contains("alter")) {
+                                || value2.toLowerCase().contains("alter ")) {
                             ErrorMessage = "SQL注入非法请求!!!";
                             return "";
                         }
@@ -178,7 +178,7 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
                 String FieldsList = "";
                 //构建SQL语句
                 if (field.split(",").length == fieldtype.split(",").length && field.split(",").length == values.split("&;@", -1).length) {//判断field,fieldtype,values长度是否一致
-                    updateStr = "update " + tablename + " set ";
+                    updateStr = "update MIDDB." + tablename + " set ";
                     for (int j = 0; j < fieldtypeArray.length; j++) {
                         if ("date".equals(fieldtypeArray[j].toString())) {
                             updateStr += field.split(",")[j] + " = convert(varchar(19),'" + values.split("&;@", -1)[j] + "',121),";
@@ -201,15 +201,15 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
                         insertValuesStr = insertValuesStr.substring(0, insertValuesStr.length() - 1);
                         FieldsList = FieldsList.substring(0, FieldsList.length() - 1);
                     }
-                    deleteStr = "delete from " + tablename;
-                    insertStr = " insert into " + tablename + "(" + FieldsList + ")" + "values(" + insertValuesStr + ")";
+                    deleteStr = "delete from MIDDB." + tablename;
+                    insertStr = " insert into MIDDB." + tablename + "(" + FieldsList + ")" + "values(" + insertValuesStr + ")";
 
                     switch (operation) {
                         case "insert":
                             AnalyseSql = insertStr + ";";
                             break;
                         case "update":
-                            updateStr += " ,createtime=getdate() "; //2022-10-14修改
+                            updateStr += " ,CREATETIME=getdate() "; //2022-10-14修改
                             AnalyseSql = updateStr + whereStr + ";";
                             break;
                         case "delete":
@@ -217,7 +217,7 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
                             AnalyseSql = deleteStr + whereStr + ";";
                             break;
                         case "select":
-                            AnalyseSql = " select count(1) total from " + tablename + " " + whereStr;
+                            AnalyseSql = " select count(1) total from MIDDB." + tablename + " " + whereStr;
                             break;
                     }
                 } else {
@@ -260,7 +260,7 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
                 res = AnalyseSql.substring(0, 299);
             }
             //日志记录
-            String sqlStr = " insert into " + tableName_Log + " (token,操作,传输数据,操作表,备注,result,sqlstr,ip) values ('" + token + "','" + operation + "','" + variable + "','" + tablename + "','" + queryResult + "','" + res + "','" + AnalyseSql + "','" + ip + "')";
+            String sqlStr = " INSERT INTO MIDDB.\"" + tableName_Log + "\" (TOKEN,操作,传输数据,操作表,备注,RESULT,SQLSTR,IP) VALUES ('" + token + "','" + operation + "','" + variable + "','" + tablename + "','" + queryResult + "','" + res + "','" + AnalyseSql + "','" + ip + "')";
 
             String Result_RZ = dbUtilSqlServer.UpadteDataBase(sqlStr);
             //日志插入失败 再次插入
@@ -274,7 +274,7 @@ public class WSForSqlServiceImpl extends Thread implements WSForSqlService {
             }
         } catch (Exception ex) {
             ex.printStackTrace();
-            ErrorMessage = ex.toString().replaceAll("'"," ").replaceAll("\\\\","\\\\\\\\") + ex.getMessage().replaceAll("'"," ").replaceAll("\\\\","\\\\\\\\");
+            ErrorMessage = ex.toString().replaceAll("'", " ").replaceAll("\\\\", "\\\\\\\\") + ex.getMessage().replaceAll("'", " ").replaceAll("\\\\", "\\\\\\\\");
             return "";
 //			queryResult = "[{\"IsSuc\":\""+"Fault"+"\",\"Msg\":\""+exception+"\",\"AllCount\":\""+0+"\",\"pageIndex\":\""+0+"\",\"CurrCount\":\"1\",\"pkid\":\"\",\"data\":"+"[{}]"+"}]" ;
 //			String res = "Fault";

+ 4 - 31
src/main/resources/application.yml

@@ -1,37 +1,10 @@
 spring:
   datasource:
-    type: com.alibaba.druid.pool.DruidDataSource
     druid:
-      driver-class-name: net.sourceforge.jtds.jdbc.Driver
-      url: jdbc:jtds:sqlserver://120.55.160.15:1433;DatabaseName=MIDDB
-#      url: jdbc:jtds:sqlserver://195.1.20.27:2433;DatabaseName=MIDDB
-      username: MIDDB
-      password: 1qaz2wsx!
-      #     配置初始化大小、最小、最大线程数
-      initialSize: 10
-      minIdle: 5
-      #     CPU核数+1,也可以大些但不要超过20,数据库加锁时连接过多性能下降
-      maxActive: 20
-      #     最大等待时间,内网:800,外网:1200(三次握手1s)
-      maxWait: 60000
-      timeBetweenEvictionRunsMillis: 60000
-      #     配置一个连接在池中最大空间时间,单位是毫秒
-      minEvictableIdleTimeMillis: 300000
-      validationQuery: SELECT 1
-      testWhileIdle: true
-      #     设置从连接池获取连接时是否检查连接有效性,true检查,false不检查
-      testOnBorrow: true
-      #     设置从连接池归还连接时是否检查连接有效性,true检查,false不检查
-      testOnReturn: true
-      #     可以支持PSCache(提升写入、查询效率)
-      poolPreparedStatements: true
-      #   配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
-      filters: stat,wall,log4j
-      #     保持长连接
-      keepAlive: true
-      maxPoolPreparedStatementPerConnectionSize: 20
-      useGlobalDataSourceStat: true
-      connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
+      driver-class-name: dm.jdbc.driver.DmDriver
+      url: jdbc:dm://localhost:5236/MIDDB
+      username: SYSDBA
+      password: 123456789
 mybatis-plus:
   mapper-locations: classpath*:mapper/*.xml,classpath*:mapper/**/*.xml
 #  configuration: