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

📄 op_student.java

📁 考勤管理系统是针对学校每个月的考勤的报表进行总结
💻 JAVA
字号:
package action;

import java.sql.SQLException;
import java.util.Vector;

import util.Student;

/**
 * 学生相关数据库操作类。
 * @author Dylin
 * @date 2006-10-3
 */
public class Op_student extends DBOption {
	private Student aStudent = null;	//学生
	private Vector<Student> stdList = null;	//学生列表
	private String sqlStr = "";			//SQL语句
	public String msg = "";		//错误信息
	
	public Op_student() {
		this.setPoolName("std");
	}
	
	/**
	 * 获取指定班级的所有学生
	 * @param clas 指定的班级
	 * @return Vector 返回的学生列表
	 */
	public Vector getClaStudents (String clas) {
		sqlStr = "select * from Students " +
				"where SCLASS ='" + clas + "'";
		
		try {
			this.rs = this.query(sqlStr);
			this.stdList = new Vector<Student>();
			
			while (rs.next()) {
				this.aStudent = new Student();
				aStudent.sId = rs.getString("SID");
				aStudent.sName = rs.getString("SNAME");
				aStudent.sClass = clas;
				aStudent.sDepart = rs.getString("SDEPART");
				stdList.addElement(aStudent);
			}
			rs.close();
			return this.stdList;
		} catch (SQLException e) {
			this.msg = "取得指定班级所有学生时出错,请稍候再试!";
			Log.writeLog(e, "action.Op_student.getClaStudents:\n\t" +
					"取得指定班级" + clas + "所有学生时出错");
			return null;
		}
	}

	/**
	 * 获取指定学生的资料
	 * @param sId 指定的学生
	 * @return Student 返回的学生
	 */
	public Student getAStudent(String sId) {
		sqlStr = "select * from STUDENTS " +
				"WHERE SID ='" + sId + "'";
		try {
			this.rs = this.query(sqlStr);
			if (rs.next()) {
				this.aStudent = new Student();
				this.aStudent.sId = sId;
				this.aStudent.sName = rs.getString("SNAME");
				this.aStudent.sClass = rs.getString("SCLASS");
				this.aStudent.sDepart = rs.getString("SDEPART");
				rs.close();
				return this.aStudent;
			} else {
				rs.close();
				this.msg = "找不到指定的同学";
				return null;
			}
		} catch (SQLException e) {
			this.msg = "找同学资料时出错";
			Log.writeLog(e , "action.Op_student.getAStudent():\n\t" +
					"找同学" + sId + "资料时出错!");
			return null;
		}
	}
	
	/**
	 * 学生登录
	 * @param sid 学号
	 * @param pw 登录密码
	 * @return Student 返回学生的资料
	 */
	public Student login(String sid, String pw) {
		if (sid == null || sid.equals("")) {
			this.msg = "请输入学号!";
			return null;
		}
		if (pw == null || pw.equals("")) {
			this.msg = "请输入密码!";
			return null;
		}
		sqlStr = "select * from students" +
				" where SID='" + sid + "'";
		try {
			this.rs = this.query(sqlStr);
			if (rs.next()) {
				if (!pw.equals(rs.getString("PASSWD"))) {
					this.msg = "密码不正确!请重新登录!";
					return null;
				}
				this.aStudent = new Student();
				this.aStudent.setSId(sid);
				this.aStudent.setSName(rs.getString("SNAME"));
				this.aStudent.setSClass(rs.getString("SCLASS"));
				this.aStudent.setSDepart(rs.getString("SDEPART"));
				
				this.rs.close();
				return this.aStudent;
			} else {
				this.msg = "登录失败,用户名不存!";
				this.rs.close();
				return null;
			}
		} catch (SQLException e) {
			this.msg = "读取学生信息时出错";
			Log.writeLog(e, "action.Op_student.login()\n\t:" +
					"读取学生" + sid + "信息时出错");
			return null;
		}
	}
	
}

⌨️ 快捷键说明

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