zoukankan      html  css  js  c++  java
  • java面向对象高级分层实例_数据库操作类

    package bdqn.studentSys.Dao.impl;
    /***
     * 学生表的数据库操作类
     */
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    import bdqn.studentSys.Dao.BaseDao;
    import bdqn.studentSys.Dao.StudentDao;
    import bdqn.studentSys.entity.Student;
    
    public class StudentDaoImpl extends BaseDao implements StudentDao {
    	
    	//查询全部
    	public List<Student> getAllStudent() {
    		// TODO Auto-generated method stub
    		List<Student> studentlist=new ArrayList<Student>();
    		String sql="select * from Student";
    		try {
    			ResultSet rs=executeQurey(sql, null);
    			while(rs.next()){
    				Student stu=new Student();
    				stu.setName(rs.getString(1));
    				stu.setPwd(rs.getString(2));
    				stu.setAge(rs.getInt(3));
    				stu.setSex(rs.getString(4));
    				studentlist.add(stu);
    			}
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}finally{
    			closeAll();
    		}
    		return studentlist;
    	}
    
    	//修改
    	public int UpdateStudent(Student stu) {
    		// TODO Auto-generated method stub
    		int rel=0;
    		String sql="update Student set name=?,pwd=?,age=?,sex=? where stuno=?";
    		Object[]prams={stu.getName(),stu.getPwd(),stu.getAge(),stu.getSex(),stu.getStuno()};
    		try {
    			rel=executeUpdate(sql, prams);
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}finally{
    			closeAll();
    		}
    		return rel;
    	}
    
    	//添加
    	public int addStudent(Student stu) {
    		int rel=0;
    		String sql="insert Student (name,pwd,age,sex) values(?,?,?,?)";
    		Object []prams={stu.getName(),stu.getPwd(),stu.getAge(),stu.getSex()};
    		try {
    			rel=executeUpdate(sql, prams);
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}finally{
    			closeAll();
    		}
    		
    		return rel;
    	}
    
    	//删除
    	public int delStudent(int stuno) {
    		int rel=0;
    		String sql="delete from Student where studentno=?";
    		Object[]prams={stuno};
    		try {
    			rel=executeUpdate(sql, prams);
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}finally{
    			closeAll();
    		}
    		return rel;
    	}
    
    }
    

  • 相关阅读:
    CSS——before和after伪元素
    CSS——滑动门技术及应用
    CSS案例3(在线教育网站)
    CSS——背景渐变
    CSS字体图标
    CSS——精灵技术
    CSS——溢出文字隐藏
    Intellij IDEA -01 如何配置项目!
    Intellij Idea -02 如何将项目工程横向排列变成纵向排列
    java8 --新特性汇总
  • 原文地址:https://www.cnblogs.com/a1111/p/6540349.html
Copyright © 2011-2022 走看看