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

📄 users.java

📁 2.打开“命令行提示符”; 3.输入mysql –u root - p命令
💻 JAVA
字号:
package com.ch9;

import java.awt.Window;
import java.sql.*;

public class users extends Execute_DB
{
	//定义类成员变量
	private long UserID;
	private String UserName;
	private String UserPassword; 
	private String Email;  
	private String Sex;      
	private String NickName;     
	private String Sign;
	private String CreateTime; 
	private String strSql;
    
    //构造函数,对成员变量进行初始化赋值
	public users()
	{       
		this.UserID=0;
		this.UserName="";
		this.UserPassword="";        
		this.Sex="";
		this.Sign="";
		this.NickName="";
		this.Email="";  
		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 + "(UserName,UserPassword,Email,Sex,NickName,Sign,CreateTime) ";        
		this.strSql=this.strSql + "values('" + this.UserName + "','" + this.UserPassword + "','" + this.Email + "','" + this.Sex + "','" + this.NickName + "','" + this.Sign + "','" + this.CreateTime + "')";
		boolean isAdd = super.exeSql(this.strSql);
		
		return isAdd;
	}
   
	//修改UserID对应的用户的信息
	public boolean modify_user_info()
	{
		this.strSql="update users set";
		this.strSql=this.strSql + " Email=" + "'" + this.Email + "',";
		this.strSql=this.strSql + " Sex=" + "'" + this.Sex + "',";
		this.strSql=this.strSql + " NickName=" + "'" + this.NickName + "',";		
		this.strSql=this.strSql + " Sign=" + "'" + this.Sign + "',";
		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 delete_user(String s_UserID)
	{
		
		this.strSql="delete from users";
		this.strSql=this.strSql + "  where UserID in ("+s_UserID+")";
		
		boolean isDelete = super.exeSql(this.strSql);      
		return isDelete;	
		
	}
   
 	//获得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.Sex=rs.getString("Sex");
				this.NickName=rs.getString("NickName");
				this.Sign=rs.getString("Sign");
				this.Email=rs.getString("Email"); 
				this.CreateTime=rs.getString("CreateTime");			    
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());            
			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.Sex=rs.getString("Sex");
				this.NickName=rs.getString("NickName");
				this.Sign=rs.getString("Sign");
				this.Email=rs.getString("Email"); 
				this.CreateTime=rs.getString("CreateTime");			    
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());   
			return false;
		}        
	}

	//验证用户名和密码是否正确
	public boolean user_valid()
	{
		this.strSql="select UserID,UserName from `users` ";
		this.strSql=this.strSql + " where UserName='" + this.UserName + "'";
		this.strSql=this.strSql + "  and UserPassword='"+ this.UserPassword + "'";         
		
		try
		{
			ResultSet rs = super.exeSqlQuery(this.strSql); 
			if (rs.next())
			{
				this.UserID=rs.getLong("UserID");
				this.UserName=rs.getString("UserName");
				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;
		}
	}
 
	//获得所有用户信息,返回一个ResultSet类型对象
	public ResultSet show_all_users()
	{
		this.strSql="select * from `users` order by UserName asc";
		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;	
	}

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

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

	//设置类成员变量Sex的值  
 	public void setSex(String Sex)
	{
		this.Sex = Sex;	
	}
   
	//获取类成员变量Sex的值  
	public String getSex()
	{
		return this.Sex;	
	}

	//设置类成员变量NickName的值  
 	public void setNickName(String NickName)
	{
		this.NickName = NickName;	
	}
   
	//获取类成员变量NickName的值  
	public String getNickName()
	{
		return this.NickName;	
	}

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

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

⌨️ 快捷键说明

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