log.java

来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 1,143 行 · 第 1/3 页

JAVA
1,143
字号
				}
				else 
				{
			   	pstm=con.prepareStatement("Update MonitoredValueInfo set MonitoredValue="+"'"+record+"'"+"where MonitoredValueID="+6);
			   i=pstm.executeUpdate();  
				}
			rsrs.close();
			ttt.closeConnect();
					
		//
		  
      		
      }                   
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			                }
	                       	}
		
      return i;     	
	}
	
	//
	public int Update17(String record){
		int i=0;
		//Date ndate = new Date();
		//String logtime=ndate.toString();
		System.out.println("record is: "+record);
		PreparedStatement pstm;
		ResultSet rsrs=null;
		//
		tableSql ttt;
		ttt=new tableSql();
		ttt.tableInit("cqjk");
		String insert="";
		int MonitoredValueID=0,MonitoredValue=0;
		try{
		
	//	pstm=con.prepareStatement("Update AgentStatusInfo set AgentWorkStatus="+"'"+running+"'");	
			
	
		//	pstm=con.prepareStatement("Update AgentStatusInfo set HostName="+"'"+address+"'"+","+"AgentName="+"'"+classname+"'"+","+"AgentWorkStatus="+"'"+running+"'"+","+"AgentConnectionStatus="+"'"+ok+"'"+","+"WritingTime="+"'"+logtime+"'");
		//
		     rsrs=ttt.recordSql("select * from MonitoredValueInfo where MonitoredValueID="+7);
				if (!rsrs.next())
				{
				insert=insert+7+","+"'"+record+"'";
				System.out.println("the insert :"+insert);
				ttt.recordInsert("insert into MonitoredValueInfo(MonitoredValueID,MonitoredValue) values("+insert+")"); 
				}
				else 
				{
			   	pstm=con.prepareStatement("Update MonitoredValueInfo set MonitoredValue="+"'"+record+"'"+"where MonitoredValueID="+7);
			   i=pstm.executeUpdate();  
				}
			rsrs.close();
			ttt.closeConnect();
					
		//
		  
      		
      }                   
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			                }
	                       	}
		
      return i;     	
	}
	//
	
	public int Update2(int record){
		int i=0;
		//Date ndate = new Date();
		//String logtime=ndate.toString();
		System.out.println("record is: "+record);
		PreparedStatement pstm;
		ResultSet rsrs=null;
		//
		tableSql ttt;
		ttt=new tableSql();
		ttt.tableInit("cqjk");
		String insert="";
		int ValueID=0,SetupValue=0;
		try{
		
	//	pstm=con.prepareStatement("Update AgentStatusInfo set AgentWorkStatus="+"'"+running+"'");	
			
	
		//	pstm=con.prepareStatement("Update AgentStatusInfo set HostName="+"'"+address+"'"+","+"AgentName="+"'"+classname+"'"+","+"AgentWorkStatus="+"'"+running+"'"+","+"AgentConnectionStatus="+"'"+ok+"'"+","+"WritingTime="+"'"+logtime+"'");
		//
		     rsrs=ttt.recordSql("select * from AgentSetupValueInfo where ValueID="+1);
				if (!rsrs.next())
				{
				insert=insert+1+","+record;
				System.out.println("the insert :"+insert);
				ttt.recordInsert("insert into AgentSetupValueInfo(ValueID,SetupValue) values("+insert+")"); 
				}
				else 
				{
			   	pstm=con.prepareStatement("Update AgentSetupValueInfo set SetupValue="+record+"where ValueID="+1);
			i=pstm.executeUpdate(); 
				}
			rsrs.close();
			ttt.closeConnect();
					
		//
		  
      		
      }                   
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			                }
	                       	}
		
      return i;     	
	}
	//
	
	//
		public int Update3(int record){
		int i=0;
		//Date ndate = new Date();
		//String logtime=ndate.toString();
		System.out.println("record is: "+record);
		PreparedStatement pstm;
		ResultSet rsrs=null;
		//
		tableSql ttt;
		ttt=new tableSql();
		ttt.tableInit("cqjk");
		String insert="";
		int ValueID=0,SetupValue=0;
		try{
		
	//	pstm=con.prepareStatement("Update AgentStatusInfo set AgentWorkStatus="+"'"+running+"'");	
			
	
		//	pstm=con.prepareStatement("Update AgentStatusInfo set HostName="+"'"+address+"'"+","+"AgentName="+"'"+classname+"'"+","+"AgentWorkStatus="+"'"+running+"'"+","+"AgentConnectionStatus="+"'"+ok+"'"+","+"WritingTime="+"'"+logtime+"'");
		//
		     rsrs=ttt.recordSql("select * from AgentSetupValueInfo where ValueID="+2);
				if (!rsrs.next())
				{
				insert=insert+2+","+record;
				System.out.println("the insert :"+insert);
				ttt.recordInsert("insert into AgentSetupValueInfo(ValueID,SetupValue) values("+insert+")"); 
				}
				else 
				{
			   	pstm=con.prepareStatement("Update AgentSetupValueInfo set SetupValue="+record+"where ValueID="+2);
			i=pstm.executeUpdate(); 
				}
			rsrs.close();
			ttt.closeConnect();
					
		//
		  
      		
      }                   
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			                }
	                       	}
		
      return i;     	
	}
	///delete records
	//
		public int UpdateUnify(){
		int i=0;
		//Date ndate = new Date();
		//String logtime=ndate.toString();
		//System.out.println("record is: "+record);
		PreparedStatement pstm;
		try{
		

			
	
		//	pstm=con.prepareStatement("Update MonitoredValueInfo set MonitoredValue="+record);
			pstm=con.prepareStatement("Update UnifyMonitoredValueInfo set Flag="+0+"where MonitoredValueID="+1);
			i=pstm.executeUpdate();  
      		
      }                   
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			}
		}
		
      return i;     	
	}
	
	//
	public int Clear(String Del){
		int j=0;
		PreparedStatement pstm;
		try{
			pstm=con.prepareStatement(Del);
			j=pstm.executeUpdate(); 
			pstm.close();
			
			
		}
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			}
		}
		
      return j;
	}
	/////
	public int ClearAll(){
		int j=0;
		PreparedStatement pstm;
		try{
			pstm=con.prepareStatement("delete from log");
			j=pstm.executeUpdate(); 
			pstm.close();
			
			
		}
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			}
		}
		
      return j;
	}
   ///display records
   public String[][] Save(ResultSet rs) {
   	int i;
   	String tmpstr;
   	int recordNumber;
   	String[][] recordArray=null;
   	try{
   		ResultSetMetaData rsmd=rs.getMetaData();
   		int numCols=rsmd.getColumnCount();
   		int no=0;
   		recordNumber=300;
   		recordArray=new String[recordNumber][numCols];
   	
   	//display each column title
   		for(i=1;i<=numCols;i++){
   			recordArray[no][i-1]=rsmd.getColumnLabel(i);
   			
   			}
   		
   		while (rs.next()){				
				no++;
				for(i=1;i<=numCols;i++){
		
					tmpstr=rs.getString(i);
		
					if(rs.wasNull()){
		
						recordArray[no][i-1]="NULL";
		
					}
					else {
						recordArray[no][i-1]=tmpstr;
		
					}
				}
		
			}
		
		}
		catch(SQLException ex){
			System.out.println("\n***SQLException333 caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			}
		}
		
		return recordArray;			   	
	}
	
	public void display(String[][] recordArray){
		int l=recordArray.length;
		int ll=recordArray[1].length;
		System.out.println("array lenth is :"+l);
		System.out.println("record lenth is :"+ll);
		for (int i=0;i<l;i++){
			for (int j=0;j<ll;j++){
				if (recordArray[i][j]!=null)
					System.out.print(recordArray[i][j]+",");
		
				else return;
			}
			System.out.println(""); ///换行显示
	 	}
	 	

	}
		
	public void closeConnect(){
		try{
			con.close();
		}
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			System.out.println("SQLState:"+ex.getSQLState());
			System.out.println("Message:"+ex.getMessage());	
			System.out.println("Vendor:"+ex.getErrorCode());
      }            	
	}
	public void closeResult(){
		try{
			rs.close();
			stmt.close();
		
		}
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			System.out.println("SQLState:"+ex.getSQLState());
			System.out.println("Message:"+ex.getMessage());	
			System.out.println("Vendor:"+ex.getErrorCode());
      }            	
	}
	
	public static void main(String args[])
	{
		log log=new log();
		log.Init("Ecmdb");
		
		log.Add("insert into log (type,describe,logtime) values ('aaaqq','bbbqqqq','cccqq')" );
		log.Add("err","aaaaaaaa");		
		
		log.ClearAll();
		log.Sql("select * from log");
	}
}


			

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?