1. 程式人生 > 實用技巧 >超市訂單管理系統,修改密碼功能實現

超市訂單管理系統,修改密碼功能實現

建議從底層向上寫

步驟:

1.UserDao介面

    //修改使用者密碼
    int updatePwd(Connection connection,int id,int password) throws SQLException;

2.UserDao介面實現類

    //修改當前使用者密碼
    public int updatePwd(Connection connection, int id, int password) throws SQLException {

        PreparedStatement pstm=null;
        int execute= 0;
        
if (connection!=null){ String sql = "update smbms.smbms_user set userPassword=? where id = ?"; Object[] params={password,id}; execute = BaseDao.execute(connection, pstm, sql, params); BaseDao.closeResource(null,pstm,null); } return execute; }

3,UserService介面

    //根據使用者id修改密碼
    boolean updatePwd(int id,int pwd);

4,UserService介面實現類

    public boolean updatePwd(int id, int pwd) {
        Connection connection=null;
        boolean flag=false;

        //修改密碼
        try {
            connection = BaseDao.getConnection();
            
if(userDao.updatePwd(connection,id,pwd)>0){ flag = true; } } catch (SQLException throwables) { throwables.printStackTrace(); }finally { BaseDao.closeResource(connection,null,null); } return flag; }