operatelog.java

来自「一个很有用的电子刊物发布系统」· Java 代码 · 共 180 行

JAVA
180
字号
package com.am;

import java.util.*;
import java.sql.*;
import java.text.*;

public class operateLog
{
    public long ID;
	public String operateType;
	public long operatorID;
	public String destination;
	public String operateDatetime;
 	public int tag;
    private String strSql;
    private Connection dbConn;
    private int errNum;
    private String errDesc;
    private SimpleDateFormat dateFormatter;

    public void operateLog()
    {
        dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
        ID=0;
    	operateType="";
    	operatorID=0;
    	destination="";
    	operateDatetime=dateFormatter.format(new java.util.Date());    
		tag=0;        
        strSql="";        
        errNum=0;
        errDesc="";
   }
   
   public void add()
   {
        strSql="insert into operatelog ";
        strSql=strSql + "(";
        strSql=strSql + "operateType,";
        strSql=strSql + "operatorID,";
        strSql=strSql + "destination,";
        strSql=strSql + "operateDatetime,";
        strSql=strSql + "tag"; 
        strSql=strSql + ") ";
		strSql=strSql + "values(";
		strSql=strSql + "'" + operateType + "',";
		strSql=strSql + "'" + operatorID + "',";
		strSql=strSql + "'" + destination + "',";
		strSql=strSql + "'" + operateDatetime + "',";	
		strSql=strSql + "'" + tag + "'";              
		strSql=strSql + ")";   
		System.out.println(strSql);    
		exeSql(strSql);

   }

   
   public void update()
   {

   		strSql="update operatelog set ";
		strSql=strSql + "operateType=" + "'" + operateType + "',";
		strSql=strSql + "operatorID=" + "'" + operatorID + "',";
		strSql=strSql + "destination=" + "'" + destination + "',";
		strSql=strSql + "operateDatetime=" + "'" + operateDatetime + "',";		
		strSql=strSql + "tag=" + "'" + tag + "'";               
		strSql=strSql + " where ID='" + ID + "'";
		exeSql(strSql);

   }

  
   public void delete()
   {
        strSql="delete from operatelog where ID='";
        strSql=strSql + this.ID + "'";

        exeSql(strSql);

   }

 
   public void enable()
   {
        strSql="update operatelog set tag=0 where ID='";
        strSql=strSql  + this.ID + "'";

        exeSql(strSql);
   }

  
   public void  disable()
   {
        strSql="update operatelog set tag=-1 where ID='";
        strSql=strSql + this.ID + "'";

        exeSql(strSql);
   }

  
   public boolean  init()
   {
    	strSql="select * from operatelog where ID=";
        strSql=strSql + "'" + this.ID + "'";
        try
		{
   			Statement stmt=dbConn.createStatement();
			ResultSet rs =stmt.executeQuery(strSql);
            if (rs.next())
            {
                ID=rs.getLong("ID");
                operateType=rs.getString("operateType");
                operatorID=rs.getLong("operatorID");
                destination=rs.getString("destination");
                operateDatetime=rs.getString("operateDatetime");               
                tag=rs.getInt("tag");
                
                this.errNum=0;
                this.errDesc="";
                return true;
            }
            else
            {
                this.errNum=-1;
                this.errDesc="init faild!";
                return false;

            }

		}
		catch(Exception ex)
		{			
            this.errNum=-1;
            this.errDesc=ex.toString();
            return false;
		}
   }

   
   public void  setConnection(Connection dbConn)
   {
   		this.dbConn=dbConn;
   }
  
   private void exeSql(String strSql)
   {
        Statement stmt=null;
        try
		{
   			stmt=dbConn.createStatement();
			stmt.executeUpdate(strSql);
            this.errNum=0;
            this.errDesc="";
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());
            this.errNum=-1;
            this.errDesc=ex.toString();

		}
        finally
        {
            stmt=null;
        }
   }

   
    public int getErrNum()
    {
        return errNum;

    }
    
    public String getErrDesc()
    {
        return errDesc;
    }
}

⌨️ 快捷键说明

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