📄 coursebean.java
字号:
package sms.bean;
import java.io.Serializable;
import java.sql.*;
import sms.db.DBAccess;
import java.util.*;
public class CourseBean implements Serializable {
private int beginTime;
private String classRoom;
private String courseId;
private String courseName;
private String courseType;
private String description;
private int endTime;
private int period;
private String teacherId;
private String teacherName;
private int term;
private int week;
public int getBeginTime() {
return beginTime;
}
public void setBeginTime(int beginTime) {
this.beginTime = beginTime;
}
public void setWeek(int week) {
this.week = week;
}
public void setTerm(int term) {
this.term = term;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public void setTeacherId(String teacherId) {
this.teacherId = teacherId;
}
public void setPeriod(int period) {
this.period = period;
}
public void setEndTime(int endTime) {
this.endTime = endTime;
}
public void setDescription(String description) {
this.description = description;
}
public void setCourseType(String courseType) {
this.courseType = courseType;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public void setClassRoom(String classRoom) {
this.classRoom = classRoom;
}
public String getClassRoom() {
return classRoom;
}
public String getCourseId() {
return courseId;
}
public String getCourseName() {
return courseName;
}
public String getCourseType() {
return courseType;
}
public String getDescription() {
return description;
}
public int getEndTime() {
return endTime;
}
public int getPeriod() {
return period;
}
public String getTeacherId() {
return teacherId;
}
public String getTeacherName() {
return teacherName;
}
public int getTerm() {
return term;
}
public int getWeek() {
return week;
}
public ArrayList queryByCourseId(String courseType, String term,
String courseId) {
String sql = "select a.course_id,a.course_name,a.type,b.name teachername,b.id teacher_id,a.term,a.week,a.period,a.begintime,a.endtime,a.classroom,a.description from course_info a,teach_info b where a.teach_id=b.id";
if (courseId != null) {
sql += " and a.course_id='" +
courseId+"'";
}
if (courseType != null) {
sql += " and a.type='" +
courseType+"'";
}
if (term != null) {
sql += " and a.term=" + term;
}
sql += " order by a.course_id";
DBAccess dba = new DBAccess();
try {
dba.getConnection();
ArrayList arrayList = new ArrayList();
ResultSet rs = null;
rs = dba.query(sql);
if (rs != null) {
while (rs.next()) {
CourseBean courseBean = new CourseBean();
courseBean.setBeginTime(rs.getInt("begintime"));
courseBean.setClassRoom(rs.getString("classroom"));
courseBean.setCourseId(rs.getString("course_id"));
courseBean.setCourseName(rs.getString("course_name"));
courseBean.setCourseType(rs.getString("type"));
courseBean.setDescription(rs.getString("description"));
courseBean.setEndTime(rs.getInt("endtime"));
courseBean.setPeriod(rs.getInt("period"));
courseBean.setTeacherName(rs.getString("teachername"));
courseBean.setTeacherId(rs.getString("teacher_id"));
courseBean.setTerm(rs.getInt("term"));
courseBean.setWeek(rs.getInt("week"));
arrayList.add(courseBean);
}
return arrayList;
}
} catch (SQLException ex) {
return null;
} finally {
dba.closeConnection();
}
return null;
}
public ArrayList queryByName(String courseType, String term,
String courseName) {
String sql = "select a.course_id,a.course_name,a.type,b.name teachername,b.id teacher_id,a.term,a.week,a.period,a.begintime,a.endtime,a.classroom,a.description from course_info a,teach_info b where a.teach_id=b.id";
if (courseName != null) {
sql += " and a.course_name='" +
courseName+"'";
}
if (courseType != null) {
sql += " and a.type='" +
courseType+"'";
}
if (term != null) {
sql += " and a.term=" + term;
}
sql += " order by a.course_id";
DBAccess dba = new DBAccess();
try {
dba.getConnection();
ArrayList arrayList = new ArrayList();
ResultSet rs = null;
rs = dba.query(sql);
if (rs != null) {
while (rs.next()) {
CourseBean courseBean = new CourseBean();
courseBean.setBeginTime(rs.getInt("begintime"));
courseBean.setClassRoom(rs.getString("classroom"));
courseBean.setCourseId(rs.getString("course_id"));
courseBean.setCourseName(rs.getString("course_name"));
courseBean.setCourseType(rs.getString("type"));
courseBean.setDescription(rs.getString("description"));
courseBean.setEndTime(rs.getInt("endtime"));
courseBean.setPeriod(rs.getInt("period"));
courseBean.setTeacherName(rs.getString("teachername"));
courseBean.setTeacherId(rs.getString("teacher_id"));
courseBean.setTerm(rs.getInt("term"));
courseBean.setWeek(rs.getInt("week"));
arrayList.add(courseBean);
}
return arrayList;
}
} catch (SQLException ex) {
return null;
} finally {
dba.closeConnection();
}
return null;
}
public ArrayList queryByNameImprecise(String courseType, String term,
String courseName) {
String sql = "select a.course_id,a.course_name,a.type,b.name teachername,b.id teacher_id,a.term,a.week,a.period,a.begintime,a.endtime,a.classroom,a.description from course_info a,teach_info b where a.teach_id=b.id";
if (courseName != null) {
courseName = "'%" + courseName + "%'";
sql += " and a.course_name like " +
courseName;
}
if (courseType != null) {
sql += " and a.type='" +
courseType+"'";
}
if (term != null) {
sql += " and a.term=" + term;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -