📄 teacherbean.java
字号:
package edu;
import java.sql.*;
//import java.text.DateFormat;
import java.text.ParseException;
//import java.text.SimpleDateFormat;
public class TeacherBean {
private int id;
private String teacher;
private String psw;
private String pswss;
private String age;
private String sex;
private int class_id;
private int grade_id;
private int subject_id;
private String address;
private String idcard;
private String mobile;
private String email;
private String allow;
private int startrow;
private int pagesize;
private String photo;
private String ask;
private String time;
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 setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public String getTeacher() {
return teacher;
}
public void setPsw(String psw) {
this.psw = psw;
}
public String getPsw() {
return psw;
}
public void setPswss(String pswss) {
this.pswss = pswss;
}
public String getPswss() {
return pswss;
}
public void setAge(String age) {
this.age = age;
}
public String getAge() {
return age;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSex() {
return sex;
}
public void setClass_id(int class_id) {
this.class_id = class_id;
}
public int getClass_id() {
return class_id;
}
public void setGrade_id(int grade_id) {
this.grade_id = grade_id;
}
public int getGrade_id() {
return grade_id;
}
public void setSubject_id(int subject_id) {
this.subject_id = subject_id;
}
public int getSubject_id() {
return subject_id;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
public void setIdcard(String idcard) {
this.idcard = idcard;
}
public String getIdcard() {
return idcard;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMobile() {
return mobile;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setAllow(String allow) {
this.allow = allow;
}
public String getAllow() {
return allow;
}
public void setTime(String s) {
this.time = s;
}
public String getTime() {
return time;
}
public boolean hasLogin(String teacher) { // 检查该老师是否已经注册
boolean f = true;
String sql = "select t_teacher from teacher where t_teacher ='"
+ teacher + "'";
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 t_id from uteacher where t_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 teacher where t_teacher ='" + teacher
+ "'and t_ask='" + ask + "'and t_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 String askfromname(String teacher) throws SQLException {
String ask = "";
String sql = "select t_ask from teacher where t_teacher='" + teacher
+ "'";
SqlBean db = new SqlBean();
ResultSet rs = db.executeQuery(sql);
if (rs.next())
ask = rs.getString(1);
return ask;
}
public String answerfromname(String teacher) throws SQLException {
String answer = "";
String sql = "select t_answer from teacher where t_teacher='" + teacher
+ "'";
SqlBean db = new SqlBean();
ResultSet rs = db.executeQuery(sql);
if (rs.next())
answer = rs.getString(1);
return answer;
}
public boolean isu(int id) throws ParseException, SQLException {
boolean is = false;
String sql = "select * from uteacher where t_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 isallow(int id) throws ParseException, SQLException {
String sql = "select t_allow from teacher where t_id='" + id + "'";
SqlBean db = new SqlBean();
ResultSet rs = db.executeQuery(sql);
while (rs.next()) {
int t_allow = rs.getInt(1);
if (t_allow == 1) {
return true;
}
return false;
}
return false;
}
public int idfromname(String teacher) throws SQLException {
int t_id = 0;
String sql = "select t_id from teacher where t_teacher='" + teacher
+ "'";
SqlBean db = new SqlBean();
ResultSet rs = db.executeQuery(sql);
if (rs.next())
t_id = rs.getInt(1);
return t_id;
}
public ResultSet getTeachers() {
String sql = "select * from teacher limit " + startrow + "," + pagesize
+ "";
SqlBean db = new SqlBean();
ResultSet rs = db.executeQuery(sql);
return rs;
}
public ResultSet getCount() {
String sql = "select count(*) from teacher";
SqlBean db = new SqlBean();
ResultSet rs = db.executeQuery(sql);
return rs;
}
public ResultSet getTeachers(int id) {
String sql = "select * from teacher where t_id='" + id + "'";
SqlBean db = new SqlBean();
ResultSet rs = db.executeQuery(sql);
return rs;
}
public void updateTeachers() {
String sql = "update teacher " + " set t_psw='" + psw + "',t_age='"
+ age + "',t_sex='" + sex + "',class_id='" + class_id
+ "',grade_id='" + grade_id + "',subject_id='" + subject_id
+ "',t_address='" + address + "',t_idcard='" + idcard
+ "',t_mobile='" + mobile + "', t_email='" + email + "' "
+ " where t_id='" + id + "' ";
SqlBean db = new SqlBean();
db.executeInsert(sql);
}
public void updateTeachers_ad() {
String sql = "update teacher " + " set t_age='" + age + "',t_sex='"
+ sex + "',class_id='" + class_id + "',grade_id='" + grade_id
+ "',subject_id='" + subject_id + "',t_address='" + address
+ "',t_idcard='" + idcard + "',t_mobile='" + mobile
+ "', t_email='" + email + "' " + " where t_id='" + id + "' ";
SqlBean db = new SqlBean();
db.executeInsert(sql);
}
public void updatePsw() {
String sql = "update teacher " + " set t_psw='" + psw
+ "'where t_teacher='" + teacher + "' ";
SqlBean db = new SqlBean();
db.executeInsert(sql);
}
public void updateTeachersask() {
String sql = "update teacher " + " set t_psw='" + psw + "',t_age='"
+ age + "',t_sex='" + sex + "',class_id='" + class_id
+ "',grade_id='" + grade_id + "',subject_id='" + subject_id
+ "',t_address='" + address + "',t_idcard='" + idcard
+ "',t_mobile='" + mobile + "', t_email='" + email
+ "',t_ask='" + ask + "',t_answer='" + answer + "' "
+ " where t_id='" + id + "' ";
SqlBean db = new SqlBean();
db.executeInsert(sql);
}
public void updateTeachersask_ad() {
String sql = "update teacher " + " set t_age='" + age + "',t_sex='"
+ sex + "',class_id='" + class_id + "',grade_id='" + grade_id
+ "',subject_id='" + subject_id + "',t_address='" + address
+ "',t_idcard='" + idcard + "',t_mobile='" + mobile
+ "', t_email='" + email + "',t_ask='" + ask + "',t_answer='"
+ answer + "' " + " where t_id='" + id + "' ";
SqlBean db = new SqlBean();
db.executeInsert(sql);
}
public void updatePhoto() {
String sql = "update teacher set t_photo='" + photo + "' where t_id='"
+ id + "'";
SqlBean db = new SqlBean();
db.executeInsert(sql);
}
public int checkTeacher(int id) {
String sql = "update teacher set t_allow=1 where t_id='" + id + "' ";
SqlBean db = new SqlBean();
int num = db.executeInsert(sql);
return num;
}
public int uncheckTeacher(int id) {
String sql = "update teacher set t_allow=0 where t_id='" + id + "' ";
SqlBean db = new SqlBean();
int num = db.executeInsert(sql);
return num;
}
public void deleteTeachers() {
String user = "teacher";
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 sql3 = "delete from uteacher where t_id ='" + id + "' ";
String sql4 = "delete from teacher where t_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(sql3);
db.executeDelete(sql4);
}
public int deleteTeachers(int id) {
int num = 0;
String user = "teacher";
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 sql3 = "delete from uteacher where t_id ='" + id + "' ";
String sql4 = "delete from teacher where t_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(sql3);
num = db.executeDelete(sql4);
return num;
}
public void addTeachers() {
String sql = "insert into teacher(t_teacher,t_psw,t_age,t_sex,class_id,grade_id,subject_id,t_address,t_idcard,t_mobile,t_email,t_ask,t_answer,t_day) "
+ "VALUES('"
+ teacher
+ "','"
+ psw
+ "','"
+ age
+ "','"
+ sex
+ "','"
+ class_id
+ "','"
+ grade_id
+ "','"
+ subject_id
+ "','"
+ address
+ "','"
+ idcard
+ "','"
+ mobile
+ "','"
+ email
+ "','"
+ ask
+ "','"
+ answer
+ "','"
+ time + "')";
SqlBean db = new SqlBean();
db.executeInsert(sql);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -