package cn.com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.com.entity.Score;
import cn.com.entity.Student;
import cn.com.utils.DBUtils;



public class StuDao {
	Connection conn;
	PreparedStatement pst;
	ResultSet rs;
	public Student stulogin(Student stu) {
		// TODO Auto-generated method stub
		
		try {
			conn = DBUtils.getConn();
			String sql = "select * from student where sid = ? and sname = ? and spwd = ?";
			pst = conn.prepareStatement(sql);
			pst.setString(1, stu.getSid());
			pst.setString(2, stu.getSname());
			pst.setString(3, stu.getSpwd());
			rs = pst.executeQuery();
			while(rs.next()){
				Student st = new Student();
				st.setSid(rs.getString("sid"));
				st.setSname(rs.getString("sname"));
				st.setSeid(rs.getString("seid"));
				st.setSpwd(rs.getString("spwd"));
				st.setSsex(rs.getInt("ssex"));
				st.setSof(rs.getString("sof"));
				st.setScountenance(rs.getString("sid"));
				st.setSchooling(rs.getString("schooling"));
				st.setStatus(rs.getInt("status"));
				st.setSxuezhi(rs.getString("sxuezhi"));
				st.setPhone(rs.getString("phone"));
				st.setMid(rs.getInt("mid"));
				st.setCid(rs.getInt("cid"));
			
				return st;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst, rs);
		}
		return null;
	}

	public List<Student> stuByshow(String sid) {
		// TODO Auto-generated method stub
		try {
			conn = DBUtils.getConn();
			String sql = "select * from student s,major m,class c where s.mid = m.mid and s.cid = c.cid and s.sid = ?";
			pst = conn.prepareStatement(sql);
			pst.setString(1, sid);
			rs = pst.executeQuery();
			List<Student> bylist = new ArrayList();
			while(rs.next()){
				Student st = new Student();
				st.setSid(rs.getString("sid"));
				st.setSname(rs.getString("sname"));
				st.setSeid(rs.getString("seid"));
				st.setSpwd(rs.getString("spwd"));
				st.setSsex(rs.getInt("ssex"));
				st.setSof(rs.getString("sof"));
				st.setScountenance(rs.getString("scountenance"));
				st.setSchooling(rs.getString("schooling"));
				st.setStatus(rs.getInt("status"));
				st.setSxuezhi(rs.getString("sxuezhi"));
				st.setPhone(rs.getString("phone"));
				st.setSphone(rs.getString("sphone"));
				st.setSqq(rs.getString("sqq"));
				st.setSmail(rs.getString("smail"));
				st.setMid(rs.getInt("mid"));
				st.setCid(rs.getInt("cid"));
				st.setMname(rs.getString("mname"));
				st.setCname(rs.getString("cname"));
				
				bylist.add(st);
				System.out.println(bylist+"???");
			}
			return bylist;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst, rs);
		}
		return null;
	}
	public Student stu2(String sid) {
		// TODO Auto-generated method stub
		
		try {
			conn = DBUtils.getConn();
			String sql = "select * from student where sid = ?";
			pst = conn.prepareStatement(sql);
			pst.setString(1, sid);
			
			rs = pst.executeQuery();
			while(rs.next()){
				Student st = new Student();
				st.setSid(rs.getString("sid"));
				st.setSname(rs.getString("sname"));
				st.setSeid(rs.getString("seid"));
				st.setSpwd(rs.getString("spwd"));
				st.setSsex(rs.getInt("ssex"));
				st.setSof(rs.getString("sof"));
				st.setScountenance(rs.getString("sid"));
				st.setSchooling(rs.getString("schooling"));
				st.setStatus(rs.getInt("status"));
				st.setSxuezhi(rs.getString("sxuezhi"));
				st.setPhone(rs.getString("phone"));
				st.setMid(rs.getInt("mid"));
				st.setCid(rs.getInt("cid"));
				st.setSmail(rs.getString("smail"));
				return st;
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst, rs);
		}
		return null;
	}
	public List<Student> spwd(String sid) {
		// TODO Auto-generated method stub
		
		try {
			conn = DBUtils.getConn();
			String sql = "select spwd from student where sid = ?";
			pst = conn.prepareStatement(sql);
			pst.setString(1, sid);
			List<Student> slist = new ArrayList<>();
			rs = pst.executeQuery();
			while(rs.next()){
				Student st = new Student();
				
				st.setSpwd(rs.getString("spwd"));
				slist.add(st);
				System.out.println(slist+"!@@@");
			}
			return slist;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst, rs);
		}
		return null;
	}
	public List<Score> stuScoreByshow(String sid) {
		// TODO Auto-generated method stub
		try {
			conn = DBUtils.getConn();
			String sql = "select * from student st,score s,teacher t where st.sid = s.sid and s.tid = t.tid and st.sid = ?";
			pst = conn.prepareStatement(sql);
			pst.setString(1, sid);
			rs = pst.executeQuery();
			List<Score> bylist = new ArrayList();
			while(rs.next()){
				Score sc = new Score();
				sc.setScid(rs.getInt("scid"));
				sc.setSyear(rs.getString("syear"));
				sc.setStem(rs.getString("stem"));
				sc.setScname(rs.getString("scname"));
				sc.setStype(rs.getInt("stype"));
				sc.setSkhfs(rs.getInt("skhfs"));
				sc.setScore(rs.getInt("score"));
				sc.setSxf(rs.getInt("sxf"));
				sc.setSid(rs.getString("sid"));
				sc.setTid(rs.getString("tid"));
				sc.setTname(rs.getString("tname"));
				bylist.add(sc);
				System.out.println(bylist+"???");
			}
			return bylist;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst, rs);
		}
		return null;
	}
	public void updateInfo(Student stu) {
		// TODO Auto-generated method stub
		try {
			conn = DBUtils.getConn();
			String sql = "update student set phone = ?,sphone = ?,sqq = ?,smail = ? where sid = ?";
			pst = conn.prepareStatement(sql);
			
			pst.setString(1, stu.getPhone());
			pst.setString(2, stu.getSphone());
			pst.setString(3, stu.getSqq());
			pst.setString(4, stu.getSmail());
			pst.setString(5, stu.getSid());
			
			pst.executeUpdate();
			System.out.println("!!!!!!!!!!");
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst);
		}
		
	}

	public void updateSpwd(Student stu) {
		// TODO Auto-generated method stub
		try {
			conn = DBUtils.getConn();
			String sql = "update student set spwd = ? where sid = ?";
			pst = conn.prepareStatement(sql);
			
			pst.setString(1, stu.getSpwd());
			
			pst.setString(2, stu.getSid());
			
			pst.executeUpdate();
			System.out.println("!!!!!!!!!!");
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst);
		}
		
	}

	public void checkDel(Student student) {
		// TODO Auto-generated method stub
		try {
			conn = DBUtils.getConn();
			String sql = "delete from student where sid = ?";
			pst = conn.prepareStatement(sql);
			pst.setString(1, student.getSid());
			pst.executeUpdate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst);
		}
	}

	public List<Student> studentByid(Student student) {
		// TODO Auto-generated method stub
		List<Student> list = new ArrayList<Student>();
		try {
			conn = DBUtils.getConn();
			String sql = "select * from student where sid = ?";
			pst = conn.prepareStatement(sql);
			
			
			
			pst.setString(1, student.getSid());
			rs = pst.executeQuery();
			while(rs.next()){
				Student st = new Student();
				st.setSid(rs.getString("sid"));
				st.setSname(rs.getString("sname"));
				st.setSeid(rs.getString("seid"));
				st.setSpwd(rs.getString("spwd"));
				st.setSsex(rs.getInt("ssex"));
				st.setSof(rs.getString("sof"));
				st.setScountenance(rs.getString("sid"));
				st.setSchooling(rs.getString("schooling"));
				st.setStatus(rs.getInt("status"));
				st.setSxuezhi(rs.getString("sxuezhi"));
				st.setPhone(rs.getString("phone"));
				st.setMid(rs.getInt("mid"));
				st.setCid(rs.getInt("cid"));
				st.setSmail(rs.getString("smail"));
				list.add(st);
			}
			return list;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst);
		}
		return null;
	}

	public void update(Student student) {
		// TODO Auto-generated method stub
		try {
			conn = DBUtils.getConn();
			
			String sql = "update student set sname = ? ,seid= ?, spwd = ?, ssex = ?, sof = ?, scountenance = ?, schooling = ?,status = ?, sxuezhi = ?, mid = ?, cid = ?  where sid = ?";
			pst = conn.prepareStatement(sql);
			pst.setString(1, student.getSname());
			pst.setString(2, student.getSeid());
			pst.setString(3, student.getSpwd());
			pst.setInt(4, student.getSsex());
			pst.setString(5, student.getSof());
			pst.setString(6, student.getScountenance());
			pst.setString(7, student.getSchooling());
			pst.setInt(8, student.getStatus());
			pst.setString(9, student.getSxuezhi());
			pst.setInt(10, student.getMid());
			pst.setInt(11, student.getCid());
			pst.setString(12, student.getSid());
			pst.executeUpdate();
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.closeResouce(conn, pst);
		}
	}
}
最近下载更多
huangzy  LV12 10月23日
3263394665  LV9 2023年11月29日
你爹正在加载中  LV4 2023年7月12日
全栈小白  LV35 2023年5月23日
ewan007  LV30 2023年2月20日
263648  LV7 2023年2月14日
stonewan  LV10 2022年11月25日
485415187  LV6 2022年11月24日
bluesky2016  LV15 2022年7月6日
pureshyness  LV6 2022年4月28日
最近浏览更多
LoveSummer  LV6 10月31日
颜菜菜  LV2 9月6日
janeqin  LV1 7月18日
TY0165  LV20 6月24日
胡闹的番茄精  LV2 6月17日
卢旯旯  LV4 6月11日
jimodeai  LV15 5月5日
周青松197  LV3 4月30日
dingyb  LV11 4月21日
AlexYHX 4月17日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友