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

📄 userbean.java

📁 在线教育平台: 从小学
💻 JAVA
字号:
package edu;

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

public class UserBean {
	private String name;

	private String psw;

	private String pswss;

	private int id;

	private String age;

	private String sex;

	private String address;

	private String email;

	private String time;

	private int startrow;

	private int pagesize;

	private String photo;

	private String ask;

	private String answer;

	public void setAsk(String ask) {
		this.ask = ask;
	}

	public String getAsk() {
		return ask;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}

	public String getAnswer() {
		return answer;
	}

	public void setPhoto(String s) {
		photo = s;
	}

	public String getPhoto() {
		return photo;
	}

	public void setStartpage(int s) {
		startrow = s;
	}

	public int getStartpage() {
		return startrow;
	}

	public void setPagesize(int s) {
		pagesize = s;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setTime(String s) {
		this.time = s;
	}

	public String getTime() {
		return time;
	}

	public void setAddress(String s) {
		address = s;
	}

	public String getAddress() {
		return address;
	}

	public void setSex(String s) {
		sex = s;
	}

	public String getSex() {
		return sex;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPsw() {
		return psw;
	}

	public void setPsw(String psw) {
		this.psw = psw;
	}

	public String getPswss() {
		return pswss;
	}

	public void setPswss(String pswss) {
		this.pswss = pswss;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getEmail() {
		return email;
	}

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

	public boolean hasLogin(String name) { // 检查该学生是否已经注册
		boolean f = true;
		String sql = "select u_name from user where u_name ='" + name + "'";
		SqlBean db = new SqlBean();
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				f = false;
			} else {
				f = true;
			}
		} catch (Exception e) {
			e.getMessage();
		}
		return f;
	}

	public boolean uhasLogin(int id) { // 检查该学生是否已经是优秀学生
		boolean f = true;
		String sql = "select u_id from uuser where u_id ='" + id + "'";
		SqlBean db = new SqlBean();
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				f = true;
			} else {
				f = false;
			}
		} catch (Exception e) {
			e.getMessage();
		}
		return f;
	}

	public boolean isfromname() {
		boolean f = false;
		String sql = "select * from user where u_name ='" + name
				+ "'and u_ask='" + ask + "'and u_answer='" + answer + "'";
		SqlBean db = new SqlBean();

		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				f = true;
			} else {
				f = false;
			}
		} catch (Exception e) {
			e.getMessage();
		}
		return f;
	}

	public boolean isu(int id) throws ParseException, SQLException {
		boolean is = false;
		String sql = "select * from uuser where u_id ='" + id + "'";
		SqlBean db = new SqlBean();
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				is = true;
			} else {
				is = false;
			}
		} catch (Exception e) {
			e.getMessage();
		}
		return is;
	}

	public boolean isforbid(int id) throws ParseException, SQLException {
		boolean is = true;
		String sql = "select u_forbid from user where u_id ='" + id + "'";
		SqlBean db = new SqlBean();
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				int forbid = rs.getInt(1);
				if (forbid == 1)
					is = true;

				else
					is = false;
			} else {
				is = true;
			}
		} catch (Exception e) {
			e.getMessage();
		}
		return is;
	}

	public int allowday(int id) throws ParseException, SQLException {
		int allowday = 0;
		String sql = "select u_allowday from user where u_id='" + id + "'";
		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		while (rs.next()) {
			String a_time = rs.getString(1);
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if (a_time != null) {
				java.util.Date date = df.parse(a_time);
				java.util.Date now = new java.util.Date();
				if ((date.getTime() > now.getTime())) {
					allowday = ((int) ((date.getTime() - now.getTime()) / (3600 * 1000 * 24))) + 1;
					return allowday;
				}
			}
			return 0;
		}
		return 0;
	}

	public boolean isallow(int id) throws ParseException, SQLException {
		String sql = "select u_allowday from user where u_id='" + id + "'";

		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		while (rs.next()) {
			String a_time = rs.getString(1);
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if (a_time != null) {
				java.util.Date date = df.parse(a_time);
				java.util.Date now = new java.util.Date();
				if ((date.getTime() > now.getTime())) {
					return true;
				}
			}
			return false;
		}
		return false;
	}

	public int idfromname(String name) throws SQLException {
		int u_id = 0;
		String sql = "select u_id from user where u_name='" + name + "'";
		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		if (rs.next())
			u_id = rs.getInt(1);
		return u_id;
	}

	public String askfromname(String name) throws SQLException {
		String ask = "";
		String sql = "select u_ask from user where u_name='" + name + "'";
		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		if (rs.next())
			ask = rs.getString(1);
		return ask;
	}

	public String answerfromname(String name) throws SQLException {
		String answer = "";
		String sql = "select u_answer from user where u_name='" + name + "'";
		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		if (rs.next())
			answer = rs.getString(1);
		return answer;
	}

	public ResultSet getCount() {
		String sql = "select count(*) from user ";
		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		return rs;
	}

	public ResultSet getUser() {
		String sql = "select * from user limit " + startrow + "," + pagesize
				+ "";
		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		return rs;
	}

	public int forbid(int id) {
		String sql = "update user set u_forbid=1 where u_id='" + id + "'";
		SqlBean db = new SqlBean();
		int f = db.executeInsert(sql);
		return f;
	}

	public int unforbid(int id) {

		String sql = "update user set u_forbid=0 where u_id='" + id + "'";
		SqlBean db = new SqlBean();
		int f = db.executeInsert(sql);
		return f;
	}

	public ResultSet getUser(int id) {
		String sql = "select * from user where u_id='" + id + "'";
		SqlBean db = new SqlBean();
		ResultSet rs = db.executeQuery(sql);
		return rs;
	}

	public void updateUser() {

		String sql = "update user " + " set u_sex='" + sex + "',u_address='"
				+ address + "',	 " + "u_psw='" + psw + "',u_age='" + age
				+ "',u_email='" + email + "'  " + " where u_id='" + id + "' ";
		SqlBean db = new SqlBean();
		db.executeInsert(sql);

	}

	public void updateUser_ad() {

		String sql = "update user " + " set u_sex='" + sex + "',u_address='"
				+ address + "',u_age='" + age + "',u_email='" + email + "'  "
				+ " where u_id='" + id + "' ";
		SqlBean db = new SqlBean();
		db.executeInsert(sql);

	}

	public void updatePsw() {

		String sql = "update user " + " set u_psw='" + psw + "'where u_name='"
				+ name + "' ";
		SqlBean db = new SqlBean();
		db.executeInsert(sql);

	}

	public void updateUserask() {

		String sql = "update user " + " set u_sex='" + sex + "',u_address='"
				+ address + "',	 " + "u_psw='" + psw + "',u_age='" + age
				+ "',u_email='" + email + "',u_ask='" + ask + "',u_answer='"
				+ answer + "'  " + " where u_id='" + id + "' ";
		SqlBean db = new SqlBean();
		db.executeInsert(sql);

	}

	public void updateUserask_ad() {

		String sql = "update user " + " set u_sex='" + sex + "',u_address='"
				+ address + "',u_age='" + age + "',u_email='" + email
				+ "',u_ask='" + ask + "',u_answer='" + answer + "'  "
				+ " where u_id='" + id + "' ";
		SqlBean db = new SqlBean();
		db.executeInsert(sql);

	}

	public void updatePhoto() {
		String sql = "update user set u_photo='" + photo + "' where u_id='"
				+ id + "'";
		SqlBean db = new SqlBean();
		db.executeInsert(sql);
	}

	public void deleteUser() {
		String user = "user";
		String sql0 = "select ask_id from ask where u_id='" + id
				+ "'and ask_sort='" + user + "'";
		String sql = "delete  from answer where ans_id ='" + id
				+ "'and ans_sort='" + user + "' ";
		String sql1 = "delete  from ask where u_id ='" + id + "'and ask_sort='"
				+ user + "' ";
		String sql2 = "delete  from carduser where u_id ='" + id + "' ";
		String sql3 = "delete  from uuser where u_id ='" + id + "' ";
		String sql4 = "delete  from user where u_id ='" + id + "' ";

		SqlBean db = new SqlBean();
		try {
			ResultSet rs = db.executeQuery(sql0);
			while (rs.next()) {
				int ask_id = rs.getInt(1);
				String sql5 = "delete  from answer where ask_id ='" + ask_id
						+ "'";
				db.executeDelete(sql5);
			}
		} catch (SQLException e) {
		}catch (NullPointerException e){}
		db.executeDelete(sql);
		db.executeDelete(sql1);
		db.executeDelete(sql2);
		db.executeDelete(sql3);
		db.executeDelete(sql4);
	}

	public int deleteUser(int id) {
		int num = 0;
		String user = "user";
		String sql0 = "select ask_id from ask where u_id='" + id
				+ "'and ask_sort='" + user + "'";
		String sql = "delete  from answer where ans_id ='" + id
				+ "'and ans_sort='" + user + "' ";
		String sql1 = "delete  from ask where u_id ='" + id + "'and ask_sort='"
				+ user + "' ";
		String sql2 = "delete  from carduser where u_id ='" + id + "' ";
		String sql3 = "delete  from uuser where u_id ='" + id + "' ";
		String sql4 = "delete  from user where u_id ='" + id + "' ";

		SqlBean db = new SqlBean();
		try {
			ResultSet rs = db.executeQuery(sql0);
			while (rs.next()) {
				int ask_id = rs.getInt(1);
				String sql5 = "delete  from answer where ask_id ='" + ask_id
						+ "'";
				db.executeDelete(sql5);
			}
		} catch (SQLException e) {
		}catch(NullPointerException e){
			
		}
		db.executeDelete(sql);
		db.executeDelete(sql1);
		db.executeDelete(sql2);
		db.executeDelete(sql3);
		num = db.executeDelete(sql4);
		return num;
	}

	public void addUser() {
		String sql = "insert into user(u_name,u_psw,u_email,u_sex,u_address,u_age,u_day,u_ask,u_answer)"
				+ "VALUES('"
				+ name
				+ "','"
				+ psw
				+ "','"
				+ email
				+ "','"
				+ sex
				+ "','"
				+ address
				+ "','"
				+ age
				+ "','"
				+ time
				+ "','"
				+ ask
				+ "','" + answer + "')";
		SqlBean db = new SqlBean();

		db.executeInsert(sql);
	}

}

⌨️ 快捷键说明

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