1 package org.lxh.mvcdemo.dao.impl; 2 3 import java.sql.Connection; 4 import java.sql.PreparedStatement; 5 import java.sql.ResultSet; 6 7 import org.lxh.mvcdemo.dao.IUserDAO; 8 import org.lxh.mvcdemo.vo.User; 9 10 public class UserDAOImpl implements IUserDAO{ 11 private Connection conn = null; 12 private PreparedStatement pstmt = null; 13 public UserDAOImpl(Connection conn){ 14 this.conn = conn; 15 } 16 17 public boolean findLogin(User user) throws Exception { 18 boolean flag = false; 19 try{ 20 String sql = "SELECT name FROM user WHERE userid=? AND password=?"; 21 this.pstmt = this.conn.prepareStatement(sql); 22 this.pstmt.setString(1, user.getUserid()); 23 this.pstmt.setString(2, user.getPassword()); 24 ResultSet rs = this.pstmt.executeQuery(); 25 if(rs.next()){ 26 user.setName(rs.getString(1)); 27 flag = true; 28 } 29 }catch(Exception e){ 30 throw e; 31 }finally{ 32 if(this.pstmt != null){ 33 try{ 34 this.pstmt.close(); 35 }catch(Exception e){ 36 throw e; 37 } 38 } 39 } 40 return flag; 41 } 42 43 public boolean resetPassword(String password) throws Exception { 44 45 boolean flag01 = true; 46 String sql = "update user set password=‘jjjj‘ where userid=‘admin‘"; 47 this.pstmt = this.conn.prepareStatement(sql); 48 if(this.pstmt.executeUpdate()>0){ 49 flag01 = true; 50 } 51 this.pstmt.close(); 52 return flag01; 53 } 54 }
时间: 2024-10-25 22:05:09