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;
}
}
java面向对象高级分层实例_数据库操作类
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
PHP面向对象高级
、静态延
PHP 面向对象 父类 子类 php