当前位置:网站首页>数据库实体类对应daoimpl,基础的增删改查。
数据库实体类对应daoimpl,基础的增删改查。
2022-08-04 05:33:00 【Jorge666】
数据库表名student,daoimpl类实现增删改查。
public class StudentDaoImpl extends BaseDao implements StudentDao {
/**
* 查询全部学生信息
*/
@Override
public List<Student> selectAll() {
List<Student> list = new ArrayList<>();
// 获取basedao里面通用的返回结果集
String sql = "select * from student";
Object[] params = {};
ResultSet resultSet = commonExecuteQuery(sql, params);
// 将rs结果转换成list集合
try {
while (resultSet.next()) {
Student student = new Student();
student.setStudentNo(resultSet.getInt("studentNo"));
student.setLoginPsd(resultSet.getString("loginPwd"));
student.setStudentName(resultSet.getString("studentName"));
student.setSex(resultSet.getString("sex"));
student.setGradeId(resultSet.getInt("gradeId"));
student.setPhone(resultSet.getString("phone"));
student.setAddress(resultSet.getString("address"));
student.setBornDate(resultSet.getString("bornDate"));
student.setEmail(resultSet.getString("email"));
student.setIdentityCard(resultSet.getString("identityCard"));
// 添加到list集合
list.add(student);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
@Override
public Student selectOne(String studentNo) {
// TODO Auto-generated method stub
return null;
}
@Override
public int insertStudent(Student student) {
int row = 0;
String sql = "insert into student "
+ "(studentNo,loginPwd,studentName,sex,gradeId,phone,address,bornDate,email,identityCard) "
+ "values(?,?,?,?,?,?,?,?,?,?)";
// 占位符参数
Object[] params = { student.getStudentNo(), student.getLoginPsd(), student.getStudentName(), student.getSex(),
student.getGradeId(), student.getPhone(), student.getAddress(), student.getBornDate(),
student.getEmail(), student.getIdentityCard() };
row = commonExecuteUpdate(sql, params);
return row;
}
@Override
public int updateStudent(Student student) {
int row = 0;
String sql = "update student set loginPwd=?,studentName=?,sex=?,gradeId=?,phone=?,address=?,bornDate=?,email=?,identityCard=?"
+ "where studentNo=?";
// 占位符参数
Object[] params = { student.getLoginPsd(), student.getStudentName(), student.getSex(), student.getGradeId(),
student.getPhone(), student.getAddress(), student.getBornDate(), student.getEmail(),
student.getIdentityCard(), student.getStudentNo() };
row = commonExecuteUpdate(sql, params);
return row;
}
@Override
public int deleteStudent(int studentNo) {
int row = 0;
String sql = "delete from student where studentNo =?";
Object[] params = { studentNo };
row = commonExecuteUpdate(sql, params);
return row;
}
@Override
public int deleteStudentByGradeId(int gradeId) {
int row = 0;
String sql = "delete from student where gradeid =?";
Object[] params = { gradeId };
row = commonExecuteUpdate(sql, params);
return row;
}
@Override
public int deleteGradeByGradeId(int gradeId) {
int row = 0;
String sql = "delete from grade where gradeid =?";
Object[] params = { gradeId };
row = commonExecuteUpdate(sql, params);
return row;
}
}
边栏推荐
猜你喜欢
随机推荐
IEEE802.X protocol suite
硬件描述语言Verilog HDL学习笔记之模块介绍
指针的运算【C语言】
JUC并发容器——跳表
Vmmem 进程(WSL2)消耗内存巨大
更改软件的默认安装位置
2020-03-27
Object.requireNonNull 方法说明
【HIT-SC-MEMO2】哈工大2022软件构造 复习笔记2
线程池原理
LeetCode_Dec_2nd_Week
库函数的模拟实现-C语言
Copy Siege Lion's Annual "Battle" | Review 2020
C语言无符号整型运算
webrtc代码解读二:音视频播放同步过程
JUC锁框架——CountDownLatch、CyclicBarrier和Semaphore
Rules.make - suitable for viewing in edit mode
安装Apache服务时出现的几个问题, AH00369,AH00526,AH00072....
线性表之动态数组(ArrayList)的自实现
基于Webrtc和Janus的多人视频会议系统开发5 - 发布媒体流到Janus服务器