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

📄 user.java

📁 struts 入门 --登陆部分源代码,数据库是SQLSERVER
💻 JAVA
字号:
package com;

import java.sql.ResultSet;
import java.util.Vector;

public class User {
	private String username = null;

	private String password = null;

	private int sex = 0;

	private String email = null;

	private String address = null;

	private String grade = null;

	public User() {
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public static boolean checkUser(DB db, String username, String password)
			throws Exception {
		String strSql;
		ResultSet rs;
		strSql = "select * from tuser where username='" + username
				+ "' and password='" + password + "'";
		rs = db.OpenSql(strSql);
		if (rs.next()) {
			return true;
		} else {
			return false;
		}

	}

	public boolean insert(DB db) throws Exception {
		String strSql;
		strSql = "insert into tuser values('" + username + "','" + password
				+ "'," + sex + ",'" + email + "','" + address + "','" + grade
				+ "')";
		if (db.ExecSql(strSql) == 0) {
			return false;
		} else {
			return true;
		}
	}

	public boolean edit(DB db) throws Exception {
		System.out.println("editing");
		String strSql;
		strSql = "update tuser set password='" + password + "', sex=" + sex
				+ ", email='" + email + "', address='" + address + "', grade='"
				+ grade + "' where username='" + username + "'";
		if (db.ExecSql(strSql) == 0) {
			return false;
		} else {
			return true;
		}
	}

	public static String getUserGrade(DB db, String username) throws Exception {
		String strSql;
		ResultSet rs;
		strSql = "select * from tuser where username='" + username + "'";
		rs = db.OpenSql(strSql);
		if (rs.next()) {
			return rs.getString("grade");
		} else {
			return null;
		}

	}

	public static Vector search(DB db, String username) throws Exception {
		Vector Users = new Vector();
		ResultSet rs;
		String strSql = null;

		strSql = "select * from tuser where username like '%" + username + "%'";
		rs = db.OpenSql(strSql);

		while (rs.next()) {
			User user = new User();

			user.setUsername(rs.getString("username"));
			user.setGrade(rs.getString("grade"));

			Users.add(user);
		}
		return Users;
	}

	public static User search(DB db, String username, String password)
			throws Exception {
		ResultSet rs;
		String strSql = null;

		strSql = "select * from tuser where username='" + username + "'";
		rs = db.OpenSql(strSql);

		User user = new User();
		if (rs.next()) {
			user.setUsername(rs.getString("username"));
			user.setPassword(rs.getString("password"));
			user.setSex(rs.getInt("sex"));
			user.setEmail(rs.getString("email"));
			user.setAddress(rs.getString("address"));
			user.setGrade(rs.getString("grade"));
		}
		return user;
	}

	public static Vector searchUsers(DB db) throws Exception {
		Vector userVector = new Vector();
		ResultSet rs;
		String strSql = null;

		strSql = "select * from user";
		rs = db.OpenSql(strSql);

		while (rs.next()) {
			User user = new User();

			user.setUsername(rs.getString("username"));
			user.setGrade(rs.getString("grade"));

			userVector.add(user);
		}

		return userVector;
	}

	public static boolean delete(DB db, String username) throws Exception {
		String strSql;
		strSql = "delete from user where username='" + username + "'";
		if (db.ExecSql(strSql) == 0) {
			return false;
		} else {
			return true;
		}
	}

	public static boolean edit(DB db, String username, String grade,
			String forumid) throws Exception {
		String strSql;
		strSql = "update user set grade='" + grade + "' where username='"
				+ username + "'";
		if (db.ExecSql(strSql) == 0) {
			return false;
		} else {
			if (!grade.equals("锟斤拷锟斤拷")) {
				strSql = "update forum set manager='" + username
						+ "' where id=" + forumid;
				db.ExecSql(strSql);
			}
			return true;
		}
	}
}

⌨️ 快捷键说明

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