📄 log.java
字号:
/**
* Title pams
* @author: dzc
* Company: hust
* Copyright: Copyright (c) 2005
* @version 1.0
* Date : 2005-05-11
* Audit encapsulation
* Filename:Audit.java
**/
package pams.system;
import pams.database.DBConnect;
import pams.util.*;
import java.sql.*;
import java.util.*;
public class Log {
public String UserName, TableName, AccessType;
public int LogNo;
public Timestamp LogTime;
public Log() {
};
public String getLogTime() {
if (this.LogTime != null)
return LogTime.toString().substring(0, 19);
else
return "";
}
public void setLogTime(String s) {
if (s != null)
this.LogTime = Timestamp.valueOf(s);
else
this.LogTime = null;
}
public String getUserName() {
return UserName;
}
public void setUserName(String s) {
this.UserName = s;
}
public String getTableName() {
return TableName;
}
public void setTableName(String s) {
this.TableName = s;
}
public String getAccessType() {
return AccessType;
}
public void setAccessType(String s) {
this.AccessType = s;
}
public String getLogNo() {
return DataConvert.IntToStr(LogNo);
}
public void setLogNo(int i) {
this.LogNo = i;
}
public String getAccessTypeDesp()
{
if (AccessType.equals("Add"))
return "添加";
else if (AccessType.equals("Modify"))
return "修改";
else if (AccessType.equals("Delete"))
return "删除";
else if (AccessType.equals("Login"))
return "登录";
else if (AccessType.equals("Logout"))
return "退出";
else
return "";
}
/*
* Add Log
*/
public static int Add(String _UserName, String _TableName, String _AccessType) {
DBConnect dbc = null;
try {
dbc = new DBConnect();
dbc.prepareStatement("INSERT INTO logs (LogTime,UserName,TableName,AccessType) VALUES (?,?,?,?)");
dbc.setTimestamp(1, DataConvert.getTspDateTime());
dbc.setString(2, _UserName);
dbc.setString(3, _TableName);
dbc.setString(4, _AccessType);
dbc.executeUpdate();
dbc.close();
return 1;
} catch (Exception e) {
System.err.println(e);
return -1;
}
}
/*
* search Log
*/
public static Vector Search(String _UserName, String _StartOpTime,
String _EndOpTime, String _AccessType) {
DBConnect dbc = null;
Vector LogVector = new Vector();
String strSQL = "SELECT * FROM logs WHERE";
if ((_UserName == "") & (_StartOpTime == "") & (_EndOpTime == "")
& (_AccessType == "")) {
strSQL = "SELECT * FROM logs";
} else {
if (_UserName != "")
strSQL = strSQL + " UserName LIKE '%" + _UserName + "%' AND";
if (_StartOpTime != "")
strSQL = strSQL + " LogTime>='" + _StartOpTime+ " 00:00:00' AND";
if (_EndOpTime != "")
strSQL = strSQL + " LogTime<='" + _EndOpTime + " 23:59:59' AND";
if (_AccessType != "")
strSQL = strSQL + " AccessType='" + _AccessType + "' AND";
strSQL = strSQL + " 1=1";
}
strSQL = strSQL + " ORDER BY LogTime DESC";
System.out.println(strSQL);
try {
dbc = new DBConnect();
dbc.prepareStatement(strSQL);
ResultSet rs = dbc.executeQuery();
while (rs.next()) {
Log log = new Log();
log.setLogNo(rs.getInt("LogNo"));
log.setUserName(rs.getString("UserName"));
log.setLogTime(rs.getString("LogTime"));
log.setAccessType(rs.getString("AccessType"));
log.setTableName(rs.getString("TableName"));
LogVector.add(log);
}
} catch (Exception e) {
System.err.println(e);
} finally {
try {
dbc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return LogVector;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -