From 7a1e39c59364ef80d68ea36c3e5aa004185077ba Mon Sep 17 00:00:00 2001 From: DELL <DELL@WIN-3EOIPEE9ML1> Date: 星期五, 23 二月 2024 09:18:35 +0800 Subject: [PATCH] 优化IEDScout 逻辑 --- iec61850_forFoShanAES_Model/src/com/iedscout/BTS61850_IEDScout_Task_Thread_SQL.java | 38 ++++++++++++++++++++++++++++++++------ 1 files changed, 32 insertions(+), 6 deletions(-) diff --git a/iec61850_forFoShanAES_Model/src/com/iedscout/BTS61850_IEDScout_Task_Thread_SQL.java b/iec61850_forFoShanAES_Model/src/com/iedscout/BTS61850_IEDScout_Task_Thread_SQL.java index 8b17e45..6385c01 100644 --- a/iec61850_forFoShanAES_Model/src/com/iedscout/BTS61850_IEDScout_Task_Thread_SQL.java +++ b/iec61850_forFoShanAES_Model/src/com/iedscout/BTS61850_IEDScout_Task_Thread_SQL.java @@ -19,15 +19,15 @@ Sql_Mysql sql = new Sql_Mysql(pool); try { res = sql.sqlMysqlQuery(sql_str); - if(!res.next()) { - sql.sqlMysqlExecute("INSERT INTO " + Sql_Mysql.Connect_Inf_Table + "(target_ip,target_port,conn_st) VALUES('127.0.0.1',102,0);"); - }else{ + if(res.next()) { int count_num = res.getInt("count_num"); if(count_num > 1) { - sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.Connect_Inf_Table + " WHERE num > 1"); + sql.sqlMysqlExecute("DELETE FROM " + Sql_Mysql.Connect_Inf_Table); sql.sqlMysqlExecute("INSERT INTO " + Sql_Mysql.Connect_Inf_Table + "(num,target_ip,target_port,conn_st) VALUES(1,'127.0.0.1',102,0);"); - }else { + }else if(count_num == 1){ sql.sqlMysqlExecute(" UPDATE " + Sql_Mysql.Connect_Inf_Table + " set conn_st = 0;"); + }else { + sql.sqlMysqlExecute("INSERT INTO " + Sql_Mysql.Connect_Inf_Table + "(num,target_ip,target_port,conn_st) VALUES(1,'127.0.0.1',102,0);"); } } } catch (SQLException e) { @@ -205,7 +205,33 @@ } public static boolean queryIed_NodeState_TableStopConnect(MysqlConnPool pool) { + String sql_str = "SELECT * FROM " + Sql_Mysql.Connect_Inf_Table +" where conn_st = 0;"; + boolean flag = false; + ResultSet res = null; + Sql_Mysql sql = new Sql_Mysql(pool); + try { + res = sql.sqlMysqlQuery(sql_str); + if(res.next()) { + flag = true; + } + } catch (SQLException e) { + sql.logger.error("BTS61850_IEDScout_Task_Thread_SQL.insertIntoIed_NodeState_Table():" + e.toString(), e); + } finally { + if(null != res) { + try { + res.close(); + } catch (SQLException e) { + sql.logger.error("BTS61850_IEDScout_Task_Thread_SQL.insertIntoIed_NodeState_Table():" + e.toString(), e); + } + } + sql.close_con(); + } + return flag; + } + + public static void main(String[] args) { + MysqlConnPool pool = new MysqlConnPool("192.168.10.82", 3360, 5); + System.out.println(queryIed_NodeState_TableStopConnect(pool));; - return false; } } -- Gitblit v1.9.1