⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 users.java

📁 实现图书管理
💻 JAVA
字号:
package mypkg;

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

public class users extends Execute_DB
{
	//定义类成员变量
	private long UserID;    
	private String UserName;       
	private String UserPassword;   
	private String CreateTime;
	private String RealName;
	private String Telephone;
	private String Email;
	private String Address;
	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.Address="";
		java.util.Date NowTime = new java.util.Date();
		this.CreateTime = NowTime.toLocaleString();
		this.strSql=""; 
	}
   
	//向users数据表中添加一条新记录
	public boolean add_user()
	{
        
		this.strSql="insert into users ";
		this.strSql=this.strSql + "(";        
		this.strSql=this.strSql + "UserName,";  
		this.strSql=this.strSql + "UserPassword,";
		this.strSql=this.strSql + "RealName,";
		this.strSql=this.strSql + "Telephone,";
		this.strSql=this.strSql + "Email,";
		this.strSql=this.strSql + "Address,";
		this.strSql=this.strSql + "CreateTime";
		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 + "'" + this.RealName + "',";
		this.strSql=this.strSql + "'" + this.Telephone + "',";
		this.strSql=this.strSql + "'" + this.Email + "',";
		this.strSql=this.strSql + "'" + this.Address +"',";
		this.strSql=this.strSql + "'" + this.CreateTime + "'";	
		this.strSql=this.strSql + ")";
		System.out.println(this.strSql);
		boolean isAdd = super.exeSql(this.strSql);		
		return isAdd;
	}
	///
	public boolean update_user()
	{     
		this.strSql="update users set "; 
		this.strSql=this.strSql + "RealName=";
		this.strSql=this.strSql + "'" + this.RealName + "',";
		this.strSql=this.strSql + "Telephone=";
		this.strSql=this.strSql + "'" + this.Telephone + "',";
		this.strSql=this.strSql + "Email=";
		this.strSql=this.strSql + "'" + this.Email + "',";
		this.strSql=this.strSql + "Address=";
		this.strSql=this.strSql + "'" + this.Address + "'";
		this.strSql=this.strSql + " where UserID='" + this.UserID + "'";
		System.out.println(this.strSql);
		boolean isAdd = super.exeSql(this.strSql);		
		return isAdd;
	}
   ////
	
   //验证用户名、密码和用户身份信息是否正确
	public boolean user_valid()
	{
		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");
				return true;
			}
			else
			{                
				return false;
			}
		}
		catch(Exception ex)
		{            
			return false;
		}       
	}
	
   
   	//判断用户名是否存在
	public boolean is_exist()
	{
		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;
		}
	}   
   
	//获取类成员变量UserID对应的用户信息
	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.Address=rs.getString("Address");
				this.CreateTime=rs.getString("CreateTime");
				this.SysRole=rs.getInt("SysRole");                
				return true;
			}
			else
			{
				return false;			
			} 
		}
		catch(Exception ex)
		{		 
			return false;
		}
	}
	///
	public boolean  initname()
	{
		this.strSql="select * from users where UserName=";
		this.strSql=this.strSql + this.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.RealName=rs.getString("RealName");
				this.Telephone=rs.getString("Telephone");
				this.Email=rs.getString("Email");
				this.Address=rs.getString("Address");
				this.CreateTime=rs.getString("CreateTime");
				this.SysRole=rs.getInt("SysRole");                
				return true;
			}
			else
			{
				return false;			
			} 
		}
		catch(Exception ex)
		{		 
			return false;
		}
	}
	//获取类UserName对应的用户信息
	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.Address=rs.getString("Address");
				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;
		}
	}
	
	//获取所有普通用户信息,返回一个ResultSet类型对象
	public ResultSet show_users()
	{
		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;        
	} 
   
	//设置类成员变量UserID的值 
	public void setUserID(long UserID)
	{
		this.UserID = UserID;	
	}   

	//获取类成员变量UserID的值  
	public long getUserID()
	{
		return this.UserID;	
	} 
	
	 //设置类成员变量UserName的值 
 	public void setUserName(String UserName)
	{
		this.UserName = UserName;	
	}   

	//获取类成员变量UserName的值  
	public String getUserName()
	{
		return this.UserName;	
	} 
	
	 //设置类成员变量UserPassword的值 
 	public void setUserPassword(String UserPassword)
	{
		this.UserPassword = UserPassword;	
	}   

	//获取类成员变量UserPassword的值  
	public String getUserPassword()
	{
		return this.UserPassword;	
	} 
	
	 //设置类成员变量CreateTime的值 
 	public void setCreateTime(String CreateTime)
	{
		this.CreateTime = CreateTime;	
	}   

	//获取类成员变量CreateTime的值  
	public String getCreateTime()
	{
		return this.CreateTime;	
	} 
	
	//设置类成员变量Address的值 
 	public void setAddress(String Address)
	{
		this.Address = Address;	
	}   

	//获取类成员变量Address的值  
	public String getAddress()
	{
		return this.Address;	
	} 
	////
	//设置类成员变量Email的值 
 	public void setEmail(String Email)
	{
		this.Email = Email;	
	}   

	//获取类成员变量Email的值  
	public String getEmail()
	{
		return this.Email;	
	} 
	
	//设置类成员变量RealName的值 
	public void setRealName(String RealName)
	{
		this.RealName = RealName;	
	}   

	//获取类成员变量RealName的值  
	public String getRealName()
	{
		return this.RealName;	
	} 

	//设置类成员变量Telephone的值 
 	public void setTelephone(String Telephone)
	{
		this.Telephone = Telephone;	
	}   

	//获取类成员变量Telephone的值  
	public String getTelephone()
	{
		return this.Telephone;	
	} 
	
	 //设置类成员变量SysRole的值 
 	public void setSysRole(int SysRole)
	{
		this.SysRole = SysRole;	
	}   

	//获取类成员变量SysRole的值  
	public int getSysRole()
	{
		return this.SysRole;	
	} 
}

⌨️ 快捷键说明

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