package com.thunder.dao.impl;
import com.thunder.dao.BaseDao;
import com.thunder.dao.MembersInfoDao;
import com.thunder.entity.MembersInfo;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* @author Think
*/
public class MembersInfoDaoImpl extends BaseDao implements MembersInfoDao {
@Override
public List<MembersInfo> query() throws Exception {
connection = super.getConnection();
String sql = "select * from membersinfo";
List<MembersInfo> list = new ArrayList<MembersInfo>();
preparedStatement = connection.prepareStatement(sql);
resultSet = preparedStatement.executeQuery();
selectGetAll(list);
//关闭文档流
super.closeAll(connection, preparedStatement, resultSet);
return list;
}
private void selectGetAll(List<MembersInfo> list) throws SQLException {
MembersInfo membersInfo;
while (resultSet.next()) {
membersInfo = new MembersInfo();
membersInfo.setId(resultSet.getInt("MID"));
membersInfo.setName(resultSet.getString("MNAME"));
membersInfo.setGender(resultSet.getString("MGENDER"));
membersInfo.setAge(resultSet.getInt("MAGE"));
membersInfo.setAddress(resultSet.getString("MADDRESS"));
membersInfo.setEmail(resultSet.getString("MEMAIL"));
list.add(membersInfo);
}
}
@Override
public MembersInfo getInfoById(Integer id) throws Exception {
connection = super.getConnection();
String sql = "select * from membersinfo where MID = ?";
MembersInfo membersInfo = null;
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
membersInfo = new MembersInfo();
membersInfo.setId(resultSet.getInt("MID"));
membersInfo.setName(resultSet.getString("MNAME"));
membersInfo.setGender(resultSet.getString("MGENDER"));
membersInfo.setAge(resultSet.getInt("MAGE"));
membersInfo.setAddress(resultSet.getString("MADDRESS"));
membersInfo.setEmail(resultSet.getString("MEMAIL"));
}
//关闭文档流
super.closeAll(connection, preparedStatement, resultSet);
return membersInfo;
}
@Override
public void updateInfo(MembersInfo membersInfo) {
String sql = "UPDATE membersinfo SET MNAME=?,MGENDER=?,MAGE=?,MADDRESS=?,MEMAIL=? WHERE MID=?;";
this.executeUpdate(sql, membersInfo.getName(), membersInfo.getGender(),
membersInfo.getAge(), membersInfo.getAddress(),
membersInfo.getEmail(), membersInfo.getId());
}
}
天元白手
- 粉丝: 1w+
- 资源: 24
最新资源
- SQL语言详细教程:从基础到高级全面解析及实际应用
- 仓库管理系统源代码全套技术资料.zip
- 计算机二级考试详细试题整理及备考建议
- 全国大学生电子设计竞赛(电赛)历年试题及备考指南
- zigbee CC2530网关+4节点无线通讯实现温湿度、光敏、LED、继电器等传感节点数据的采集上传,网关通过ESP8266上传远程服务器及下发控制.zip
- 云餐厅APP项目源代码全套技术资料.zip
- vscode 翻译插件开发,选中要翻译的单词,使用快捷键Ctrl+Shift+T查看翻译
- mrdoc-alpine0.9.2
- ACMNOICSP比赛经验分享:从知识储备到团队协作的全面指南
- 云餐厅项目源代码全套技术资料.zip
- 基于STM32的数字闹钟系统的仿真和程序
- 混合信号设计中DEF文件创建流程
- 美国大学生数学建模竞赛(美赛)详细教程:从组队到赛后总结全攻略
- 病媒生物孳生地调查和治理工作方案.docx
- 保姆的工作标准.docx
- 病媒生物防制指南.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈