📄 users.java
字号:
package dlut;
import java.sql.*;
public class Users extends ExecuteDB {
private long userID;
private String userName;
private String userPassword;
private String createTime;
private String realName;
private String telephone;
private String email;
private int sysRole;
private String strSql;
public Users() {
this.userID = 0;
this.userName = "";
this.userPassword = "";
this.sysRole = 0;
this.realName = "";
this.telephone = "";
this.email = "";
this.strSql = "";
}
public boolean addUser() {
this.strSql = "insert into users ";
this.strSql = this.strSql + "(";
this.strSql = this.strSql + "UserName,";
this.strSql = this.strSql + "UserPassword,";
this.strSql = this.strSql + "CreateTime,";
this.strSql = this.strSql + "RealName,";
this.strSql = this.strSql + "Telephone,";
this.strSql = this.strSql + "Email,";
this.strSql = this.strSql + "SysRole";
this.strSql = this.strSql + ") ";
this.strSql = this.strSql + "values(";
this.strSql = this.strSql + "'" + this.userName + "',";
this.strSql = this.strSql + "'" + this.userPassword + "',";
this.strSql = this.strSql + "Sysdate" + ",";
this.strSql = this.strSql + "'" + this.realName + "',";
this.strSql = this.strSql + "'" + this.telephone + "',";
this.strSql = this.strSql + "'" + this.email + "',";
this.strSql = this.strSql + "'" + this.sysRole + "'";
this.strSql = this.strSql + ")";
System.out.println(this.strSql);
boolean isAdd = super.exeSql(this.strSql);
return isAdd;
}
public boolean userValid() {
this.strSql = "select UserID,UserName,SysRole from users ";
this.strSql = this.strSql + " where UserName='" + this.userName + "'";
this.strSql = this.strSql + " and UserPassword='" + this.userPassword
+ "'";
this.strSql = this.strSql + " and SysRole='" + this.sysRole + "'";
System.out.println(this.strSql);
try {
ResultSet rs = super.exeSqlQuery(this.strSql);
if (rs.next()) {
this.userID = rs.getLong("UserID");
this.userName = rs.getString("UserName");
this.sysRole = rs.getInt("SysRole");
rs.close();
return true;
} else {
return false;
}
} catch (Exception ex) {
return false;
}
}
public boolean isExist() {
this.strSql = "select * from users ";
this.strSql = this.strSql + " where UserName='" + this.userName + "'";
try {
ResultSet rs = super.exeSqlQuery(this.strSql);
if (rs.next()) {
return true;
} else {
return false;
}
} catch (Exception ex) {
return false;
}
}
public boolean init() {
this.strSql = "select * from users where UserID=";
this.strSql = this.strSql + this.userID;
try {
ResultSet rs = super.exeSqlQuery(this.strSql);
if (rs.next()) {
this.userID = rs.getLong("UserID");
this.userName = rs.getString("UserName");
this.userPassword = rs.getString("UserPassword");
this.realName = rs.getString("RealName");
this.telephone = rs.getString("Telephone");
this.email = rs.getString("Email");
this.createTime = rs.getString("CreateTime");
this.sysRole = rs.getInt("SysRole");
return true;
} else {
return false;
}
} catch (Exception ex) {
return false;
}
}
public String getPassword() {
this.strSql = "select UserPassword from users where UserName='"
+ userName + "' and Telephone =" + this.telephone
+ " and Email='" + this.email + "'and Sysrole=" + 0;
System.out.println(this.strSql);
try {
ResultSet rs = super.exeSqlQuery(this.strSql);
if (rs.next()) {
return rs.getString("UserPassword");
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return null;
}
public boolean init(String UserName) {
this.strSql = "select * from users where UserName like ";
this.strSql = this.strSql + "'" + UserName + "'";
try {
ResultSet rs = super.exeSqlQuery(this.strSql);
if (rs.next()) {
this.userID = rs.getLong("UserID");
this.userName = rs.getString("UserName");
this.userPassword = rs.getString("UserPassword");
this.createTime = rs.getString("CreateTime");
this.email = rs.getString("Email");
this.realName = rs.getString("RealName");
this.telephone = rs.getString("Telephone");
this.sysRole = rs.getInt("SysRole");
return true;
} else {
return false;
}
} catch (Exception ex) {
return false;
}
}
public ResultSet showUsers() {
this.strSql = "select * from users where SysRole = ";
this.strSql = this.strSql + this.sysRole;
ResultSet rs = null;
try {
rs = super.exeSqlQuery(this.strSql);
} catch (Exception ex) {
System.out.println(ex.toString());
}
return rs;
}
public void setUserID(long UserID) {
this.userID = UserID;
}
public long getUserID() {
return this.userID;
}
public void setUserName(String UserName) {
this.userName = UserName;
}
public String getUserName() {
return this.userName;
}
public void setUserPassword(String UserPassword) {
this.userPassword = UserPassword;
}
public String getUserPassword() {
return this.userPassword;
}
public void setCreateTime(String CreateTime) {
this.createTime = CreateTime;
}
public String getCreateTime() {
return this.createTime;
}
public void setEmail(String Email) {
this.email = Email;
}
public String getEmail() {
return this.email;
}
public void setRealName(String RealName) {
this.realName = RealName;
}
public String getRealName() {
return this.realName;
}
public void setTelephone(String Telephone) {
this.telephone = Telephone;
}
public String getTelephone() {
return this.telephone;
}
public void setSysRole(int SysRole) {
this.sysRole = SysRole;
}
public int getSysRole() {
return this.sysRole;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -