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

📄 sqluser.java

📁 mysql+连接池+JavaBean 实现用户注册登陆系统
💻 JAVA
字号:
package cn.register.user;

import cn.register.MD5;
import cn.register.db.DBConnect;

public class SqlUser extends AbstractUser{

    //确认两次输入的密码是否相等
	//private boolean checkRPwd(String password, String rpassword)
	public boolean checkRPwd(String password, String rpassword)
	{
		if(password !=null && rpassword != null){
			if(password.equals(rpassword))
				return true;
			else 
				return false;
		}else
			return false;
	}
 
    //注册用户:
    public boolean saveUser(User user){
		String User_id = user.getUser_id();
		String Password = user.getPassword();
		String Name = user.getName();
		String Sex = user.getSex();
		long   Birth = user.getBirth();
		String Description = user.getDescription();
		String str = "insert into users values('"
		             +User_id  + "','"
					 +Password + "','"
					 +Name+      "','"
					 +Sex+       "',"
					 +Birth+     ",'"
					 +Description+   "')";
		try{
			DBConnect dbconnect = new DBConnect();
			dbconnect.excuteUpdate(str);
			return true;		
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		
    }
    
	//根据用户ID将用户信息传入User接口内保存
	public User getUser(String ID){
		//User user = null;
		String str = "select * from users where USER_ID='"+ID+"'";
		//String str = "select * from users where USER_ID='jkh' ";
		try{
			DBConnect dbconnect = new DBConnect();
			dbconnect.excuteQuery(str);
			if(dbconnect.next()){
				this.setUser_id(dbconnect.getString(1));
				this.setPassword(dbconnect.getString(2));
				setName(dbconnect.getString(3));
				setSex(dbconnect.getString(4));
				setBirth(dbconnect.getLong(5));
				setDescription(dbconnect.getString(6));
			}
		}catch(Exception e){
			e.printStackTrace();
		}	
		return this;    //若无用户信息则返回null.
	}


    //存在用户返回0  不存在用户返回1 密码错误返回2
	public int checkUser(String ID, String password){
		int index = 0;          
		User user = getUser(ID);
		//if(user != null){
		if(user.getUser_id() != null){
			if (user.getPassword().equals(MD5.toMD5(password)))
				index = 0;
			else 
				index = 2;
		}else
			index = 1;

		return index;
	}


/*	public int checkUser(String ID, String password){
		int index = 0;          
		User user = getUser(ID);
		//if(user == null)
		if (user.getUser_id()==null)
				index = 10;
		else 
				index = 2;
		
		//else
		//	index = 1;

		return index;
	} 
*/
}

⌨️ 快捷键说明

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