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

📄 user.java

📁 一个网购物系统有JAVA 写成...稍加修改就可以成为毕业设计用..希望对你们有用
💻 JAVA
字号:
package com.wssd;

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

public class User extends ExecuteDB
{
	//定义类成员变量
	private long UserID;    
	private String UserName;       
	private String UserPassword;   
	private String CreateTime;
	private String RealName;
	private String Telephone;
	private String Email;
	private String Role;   
	private String strSql;
    
    //初始化类成员变量
	public User()
	{
		this.UserID=0;        
		this.UserName="";		
		this.UserPassword="";		
		this.Role="0";	
		this.RealName="";
		this.Telephone="";
		this.Email="";
		java.util.Date NowTime = new java.util.Date();
		this.CreateTime = NowTime.toLocaleString();
		this.strSql=""; 
	}
   
	//向users数据表中添加一条新记录
	public boolean add()
	{
		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 + "Role";               
		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.CreateTime + "',";
		this.strSql=this.strSql + "'" + this.RealName + "',";
		this.strSql=this.strSql + "'" + this.Telephone + "',";
		this.strSql=this.strSql + "'" + this.Email + "',";
		this.strSql=this.strSql + "'" + this.Role + "'";	
		this.strSql=this.strSql + ")";
		System.out.println(this.strSql);
		boolean isAdd = super.exeSql(this.strSql);		
		return isAdd;
	}
	
	   
	//修改UserID对应的用户的信息
	public boolean modify_info()
	{
		this.strSql="update users set";
		this.strSql=this.strSql + " RealName=" + "'" + this.RealName + "',";
		this.strSql=this.strSql + " Telephone=" + "'" + this.Telephone + "',";
		this.strSql=this.strSql + " Email=" + "'" + this.Email + "',";
		this.strSql=this.strSql + " CreateTime=" + "'" + this.CreateTime + "'";
		this.strSql=this.strSql + " where UserID='" + this.UserID + "'";
		boolean isUpdate = super.exeSql(this.strSql);
		
		return isUpdate;
	}

	//修改UserID对应的用户的密码
 	public boolean modify_UserPassword()
 	{
		this.strSql="update users set ";
		this.strSql=this.strSql + "UserPassword=" + "'" + this.UserPassword + "'";
		this.strSql=this.strSql + " where UserID='" + this.UserID + "'";
		boolean isUpdatekey = super.exeSql(this.strSql);

		return isUpdatekey;
	}
  
	//验证用户名和密码是否正确
	public boolean valid()
	{
		this.strSql="select UserID,UserName,Role from `users` ";
		this.strSql=this.strSql + " where UserName='" + this.UserName + "'";
		this.strSql=this.strSql + "  and UserPassword='"+ this.UserPassword + "'";         

		try
		{
			ResultSet rs = super.exeQuery(this.strSql); 
			if (rs.next())
			{
				this.UserID=rs.getLong("UserID");
				this.UserName=rs.getString("UserName");
				this.Role = rs.getString("Role");
				return true;
			}
			else
			{                
				return false;
			}
		}
		catch(Exception ex)
		{            
			return false;
		}       
	}
	
   
   	//判断用户名是否存在
	public boolean exist()
	{
		this.strSql="select * from users ";
		this.strSql=this.strSql + " where UserName='" + this.UserName + "'";  

		try
		{
			ResultSet rs = super.exeQuery(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.exeQuery(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.Role=rs.getString("Role");                
				return true;
			}
			else
			{
				return false;			
			} 
		}
		catch(Exception ex)
		{		 
			return false;
		}
	}
	
	//获取类UserName对应的用户信息
	public boolean  init_byUserName()
	{
		this.strSql="select * from users where UserName like ";
		this.strSql=this.strSql + "'" + this.UserName + "'";        
		try
		{
			ResultSet rs = super.exeQuery(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.Role=rs.getString("Role");                
				return true;
			}
			else
			{
				return false;			
			} 
		}
		catch(Exception ex)
		{		 
			return false;
		}
	}	
   
	//设置类成员变量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;	
	} 
	
	//设置类成员变量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;	
	} 
	
	 //设置类成员变量Role的值 
 	public void setRole(String Role)
	{
		this.Role = Role;	
	}   

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

⌨️ 快捷键说明

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