首页>代码>jsp+servlet开发java web学生成绩管理系统>/SSMS/src/dao/Impl/StudentDaoImpl.java
package dao.Impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import model.PageBean;
import model.Student;
import dao.StudentDao;
import db.DBCon;

public class StudentDaoImpl implements StudentDao {

	private DBCon dbCon = new DBCon();
	private Student student;
	private PageBean pageBean;

	public int addStu(Student student) {
		String sql = "insert into student(stu_num,stu_name,stu_sex,stu_age,stu_class,major,department) values('"
				+ student.getStuNum()
				+ "','"
				+ student.getStuName()
				+ "','"
				+ student.getStuSex()
				+ "',"
				+ student.getStuAge()
				+ ",'"
				+ student.getStuClass()
				+ "','"
				+ student.getMajor()
				+ "','"
				+ student.getDepartment() + "')";
		int rs = dbCon.query(sql);

		return rs;
	}

	public int deleteStu(String stuNum) {
		String sql = "delete from student where stu_num='" + stuNum + "'";
		int rs = dbCon.query(sql);
		return rs;
	}

	public int editStu(Student student) {
		String sql = "update student set stu_name='" + student.getStuName()
				+ "',stu_sex='" + student.getStuSex() + "',stu_age="
				+ student.getStuAge() + ",stu_class='" + student.getStuClass()
				+ "',major='" + student.getMajor() + "',department='"
				+ student.getDepartment() + "' where stu_num='"
				+ student.getStuNum() + "'";
		int rs=dbCon.query(sql);
		return rs;
	}

	public List findAll() {
		List<Student> list = new ArrayList<Student>();
		String sql = "select * from student";
		ResultSet rs = dbCon.find(sql);
		try {
			while (rs.next()) {
				int stuID = rs.getInt("stu_id");
				String stuNum = rs.getString("stu_num");
				String stuName = rs.getString("stu_name");
				String stuSex = rs.getString("stu_sex");
				int stuAge = rs.getInt("stu_age");
				String stuClass = rs.getString("stu_class");
				String major = rs.getString("major");
				String department = rs.getString("department");
				student = new Student(stuID, stuNum, stuName, stuSex, stuAge,
						stuClass, major, department);
				list.add(student);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	public List findOne(String stuNum) {
		List<Student> list = new ArrayList<Student>();
		String sql="select * from student where stu_num='"+stuNum+"'";
		ResultSet rs=dbCon.find(sql);
		try {
			while(rs.next()){
				int stuID = rs.getInt("stu_id");
				String stunum = rs.getString("stu_num");
				String stuName = rs.getString("stu_name");
				String stuSex = rs.getString("stu_sex");
				int stuAge = rs.getInt("stu_age");
				String stuClass = rs.getString("stu_class");
				String major = rs.getString("major");
				String department = rs.getString("department");
				student = new Student(stuID, stunum, stuName, stuSex, stuAge,
						stuClass, major, department);
				list.add(student);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	//pageNo当前页码,pageCount每页显示总条数
	public PageBean stuListPage(int pageNo, int pageCount) {
		int totalCount=0;
		List<Student> list = new ArrayList<Student>();
		String sql="select * from student limit "+((pageNo-1)*pageCount)+","+pageCount;
		String sqlCount="select count(*) from student";
		
		try {
			ResultSet rs=dbCon.find(sql);
			while(rs.next()){
				int stuID = rs.getInt("stu_id");
				String stuNum = rs.getString("stu_num");
				String stuName = rs.getString("stu_name");
				String stuSex = rs.getString("stu_sex");
				int stuAge = rs.getInt("stu_age");
				String stuClass = rs.getString("stu_class");
				String major = rs.getString("major");
				String department = rs.getString("department");
				student = new Student(stuID, stuNum, stuName, stuSex, stuAge,
						stuClass, major, department);
				list.add(student);
			}
			rs=dbCon.find(sqlCount);
			while(rs.next()){
				totalCount=rs.getInt(1); 
			}
			pageBean=new PageBean(list ,  totalCount,  pageNo,  pageCount);
		} catch (SQLException e) {
			dbCon.close();
			e.printStackTrace();
		}
		return pageBean;
	}

}
最近下载更多
dfkdjfb  LV1 2023年12月15日
李朝磊  LV18 2023年12月12日
17558474454  LV1 2023年12月4日
15797970926  LV1 2023年11月28日
刘洋66666  LV1 2023年11月5日
jiemomo  LV12 2023年11月2日
泰州市斑驳时光  LV4 2023年9月16日
husiyu  LV3 2023年9月8日
流连瓦盖法  LV7 2023年6月23日
最近浏览更多
wsq123456 前天
暂无贡献等级
GQpqwe 8月14日
暂无贡献等级
heaner 8月10日
暂无贡献等级
琐事消极 7月1日
暂无贡献等级
車厘子 6月28日
暂无贡献等级
TY0165  LV20 6月22日
小辰同学 6月21日
暂无贡献等级
时光海  LV2 6月21日
xjw2215631 6月12日
暂无贡献等级
cptbuptp 6月7日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友