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

📄 user.java

📁 该系统利用Java实现简单论坛功能
💻 JAVA
字号:
package ch11.bean;

import java.util.*;
import java.sql.Connection;
import java.sql.ResultSet;
import ch11.util.*;

public class User {  
	private String username = null;	
	private String password = null;	
	private String nickname = null;	
	private String sex = null;	
	private String birthyear = null;
	private String birthmonth = null;	
	private String birthday = null;	
	private String email = null;	
	private String mobile = null;	
	private String signiture = null;
	private String grade = null;	
	private int score = 0;	
	
	 
	public User(){}
	public void setUsername(String username) {
		this.username = username;
	}
	  
	public String getUsername() {
		return username;
	}
	  
	public void setPassword(String password) {
		this.password = password;
	}
	  
	public String getPassword() {
		return password;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	  
	public String getNickname() {
		return nickname;
	}
	
	public void setSex(String sex) {
		this.sex = sex;
	}
	  
	public String getSex() {
		return sex;
	}
	
	public void setBirthyear(String birthyear) {
		this.birthyear = birthyear;
	}
	  
	public String getBirthyear() {
		return birthyear;
	}
	
	public void setBirthmonth(String birthmonth) {
		this.birthmonth = birthmonth;
	}
	  
	public String getBirthmonth() {
		return birthmonth;
	}
	
	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}
	  
	public String getBirthday() {
		return birthday;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	  
	public String getEmail() {
		return email;
	}
	
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	  
	public String getMobile() {
		return mobile;
	}
	
	public void setSigniture(String signiture) {
		this.signiture = signiture;
	}
	  
	public String getSigniture() {
		return signiture;
	}
	
	public void setGrade(String grade) {
		this.grade = grade;
	}
	  
	public String getGrade() {
		return grade;
	}
	public void setScore(int score) {
		this.score = score;
	}
	  
	public int getScore() {
		return score;
	}
	
	public static boolean checkUser(DB db,String name,String psw) throws Exception{
        String strSql;
		ResultSet rs;
        strSql = "select * from user where username='"
					+ name + "' and password='" + psw + "'";
		rs = db.execQuery(strSql);  
		if ( rs.next()) {
			return true;
		}
		else{
			return false;
		}
	
	}
	
	public boolean Insert(DB db) throws Exception{
        String strSql;
        strSql = "insert into user values('" 
        		+ username 	+"','"
				+ password 	+"','"
				+ nickname 	+"','"
				+ sex 		+"','"
				+ birthyear +"','"
				+ birthmonth+"','"
				+ birthday 	+"','"
				+ email 	+"','"
				+ mobile 	+"','"
				+ signiture +"','普通用户',100)";
		if ( db.execUpdate(strSql)==0) {
			return false;
		}
		else{
			return true;
		}
	}
		
	public static String  getUserGrade(DB db,String name) throws Exception{
        String strSql;
		ResultSet rs;
        strSql = "select * from user where username='"
					+ name + "'";
		rs = db.execQuery(strSql);  
		if ( rs.next()) {
			return rs.getString("usergrade");
		}
		else{
			return null;
		}
	
	}
	
	public static Vector Search(DB db ,String username) throws Exception{
		Vector Users = new Vector();
		ResultSet rs,rsNest;
        String strSql=null;
		
        strSql = "select * from user where username like '%" + username + "%'";
		rs = db.execQuery(strSql);
		
		while  (rs.next()){
			User user = new User();
			
			user.setUsername(rs.getString("username")) ;
			user.setGrade(rs.getString("usergrade")) ;
			
			Users.add(user);
		}
		return Users;
	}
	
	public static Vector SearchMaster(DB db) throws Exception{
		Vector Users = new Vector();
		ResultSet rs,rsNest;
        String strSql=null;
		
        strSql = "select * from user where usergrade = '斑竹'";
		rs = db.execQuery(strSql);
		
		while  (rs.next()){
			User user = new User();
			
			user.setUsername(rs.getString("username")) ;
			user.setGrade(rs.getString("usergrade")) ;
			
			Users.add(user);
		}
					
		return Users;
	}
	public static boolean Delete(DB db,String username) throws Exception{
        String strSql;
        strSql = "delete from user where username='"+username+"'";
		if ( db.execUpdate(strSql)==0) {
			return false;
		}
		else{
			return true;
		}
	}
		
	public static boolean Edit(DB db,String username,String grade,String sort) throws Exception{
        String strSql;
        strSql = "update user set usergrade='"+grade+"' where username='"+username+"'";
		if ( db.execUpdate(strSql)==0) {
			return false;
		}
		else{
        	if (!grade.equals("斑竹")){
        		strSql = "update sort set master='' where master='"+username+"'";
				db.execUpdate(strSql);
        	}
			return true;
		}
	}	
}

⌨️ 快捷键说明

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