| | |
| | | import java.security.interfaces.RSAKey; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.base.Com; |
| | | import com.modbus.data.MyModbusMaster; |
| | | import com.sql.MysqlConnPool; |
| | | import com.sql.Sql_Mysql; |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 插入或更新当前设备的连接状态 |
| | | * @param pool |
| | | * @param dev_id |
| | | * @param master |
| | | */ |
| | | public static void insertOrUpdateDeviceConnectState(MysqlConnPool pool,int dev_id,MyModbusMaster master) { |
| | | String sql_str_sel = " SELECT * FROM "+Sql_Mysql.Tb_Device_ConnectState+" WHERE dev_id = " + dev_id; |
| | | String sql_str_ins = " INSERT INTO "+Sql_Mysql.Tb_Device_ConnectState+"(dev_id,connect_en,record_time) values("+dev_id+","+master.getConnectState()+",'"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"');"; |
| | | String sql_str_upd = " UPDATE "+Sql_Mysql.Tb_Device_ConnectState+" SET connect_en = "+master.getConnectState()+",record_time='"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"' WHERE dev_id = " + dev_id; |
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn()); |
| | | ResultSet res = null; |
| | | try { |
| | | res = sql.sqlMysqlQuery(sql_str_sel); |
| | | if(res.next()) { |
| | | sql.sqlMysqlExecute(sql_str_upd); |
| | | }else { |
| | | sql.sqlMysqlExecute(sql_str_ins); |
| | | } |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if(res != null) { |
| | | try { |
| | | res.close(); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | } |
| | | } |