public boolean doCreate(Member member) throws Exception {
String sql = "insert into member01(mid,name,age,phone,birthday,note) values(?,?,?,?,?,?)";
this.preparedStatement = this.connection.prepareStatement(sql);
this.preparedStatement.setString(1, member.getMid());
this.preparedStatement.setString(2, member.getName());
this.preparedStatement.setInt(3, member.getAge());
this.preparedStatement.setString(4, member.getPhone());
this.preparedStatement.setDate(5, new java.sql.Date(member.getBrithday().getTime()));
this.preparedStatement.setString(6, member.getNote());
return this.preparedStatement.executeUpdate() > 0;
}
public boolean doUpdate(Member member) throws Exception {
String sql = "update member01 set name=?,age=?,phone=?,birthday=?,note=? where mid=?";
this.preparedStatement = this.connection.prepareStatement(sql);
this.preparedStatement.setString(1, member.getName());
this.preparedStatement.setInt(2, member.getAge());
this.preparedStatement.setString(3, member.getPhone());
this.preparedStatement.setDate(4, new java.sql.Date(member.getBrithday().getTime()));
this.preparedStatement.setString(5, member.getNote());
this.preparedStatement.setString(6, member.getMid());
return this.preparedStatement.executeUpdate() > 0;
}
public boolean doRemoveBatch(Set<String> ids) throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("delete from member01 where mid in(");
Iterator<String> iterator = ids.iterator();
while (iterator.hasNext()) {
buffer.append("'").append(iterator.next()).append(")");
}
buffer.delete(buffer.length() - 1, buffer.length()).append("");
this.preparedStatement = this.connection.prepareStatement(buffer.toString());
return this.preparedStatement.executeUpdate() == ids.size();
}
public Member findById(String id) throws Exception {
Member member = null;
String sql = "select mid,name,age,phone,birthday,note from member01 where mid=?";
this.preparedStatement = this.connection.prepareStatement(sql);
this.preparedStatement.setString(1, id);
ResultSet resultSet = this.preparedStatement.executeQuery();
if (resultSet.next()) {
member = new Member();
member.setMid(resultSet.getString(1));
member.setName(resultSet.getString(2));
member.setAge(resultSet.getInt(3));
member.setPhone(resultSet.getString(4));
member.setBrithday(resultSet.getDate(5));
member.setNote(resultSet.getString(6));
}
return member;
}
public List<Member> findByAll() throws Exception {
List<Member> members = new ArrayList<>();
String sql = "select mid,name,age,phone,birthday,note from member01";
this.preparedStatement = this.connection.prepareStatement(sql);
ResultSet resultSet = this.preparedStatement.executeQuery();
while (resultSet.next()) {
Member member = new Member();
member.setMid(resultSet.getString(1));
member.setName(resultSet.getString(2));
member.setAge(resultSet.getInt(3));
member.setPhone(resultSet.getString(4));
member.setBrithday(resultSet.getDate(5));
member.setNote(resultSet.getString(6));
members.add(member);
}
return members;
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦