• 用户界面的代码


    package cn.edu.zucc.personplan.comtrol.example;
    
    import cn.edu.zucc.personplan.itf.IUserManager;
    import cn.edu.zucc.personplan.model.BeanUser;
    import cn.edu.zucc.personplan.util.BaseException;
    import java.util.Date;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    import cn.edu.zucc.personplan.util.BaseException;
    import cn.edu.zucc.personplan.util.BusinessException;
    import cn.edu.zucc.personplan.util.DBUtil;
    import cn.edu.zucc.personplan.util.DbException;
    
    import java.sql.Connection;
    
    
    
    
    
    public class ExampleUserManager implements IUserManager {
    
        @Override
        public BeanUser reg(String userid, String pwd,String pwd2) throws BaseException {
            // TODO Auto-generated method stub
            Connection conn = null;
            try {
                if (!pwd.equals(pwd2)) {
                    throw new BaseException("密码不一致!!!");
                }
                BeanUser zz=new BeanUser();
                zz.setUser_id(userid);
                zz.setUser_pwd(pwd);
                zz.setRegister_time(new java.util.Date());
                conn = DBUtil.getConnection();
                String sql = "insert into tbl_user(user_id,user_pwd,register_time)values('"+
                userid+"','"+pwd+"','"+"20200701"+"');";
                //System.out.println(sql);
                java.sql.Statement st = conn.createStatement();
                st.execute(sql);
            }
            catch (SQLException e){
                e.printStackTrace();
                throw new DbException(e);
            }
            finally {
                if (conn != null) 
                    try {
                        conn.close();
                    }
                catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }
    
        
        @Override
        public BeanUser login(String userid, String pwd) throws BaseException {
            // TODO Auto-generated method stub
            Connection conn = null;
            try {
                BeanUser zz=new BeanUser();
                zz.setUser_id(userid);
                conn = DBUtil.getConnection();
                String sql = "select user_pwd from tbl_user where user_id = '"+userid+"'";
                System.out.println(sql);
             
                java.sql.PreparedStatement pst = conn.prepareStatement(sql);
                java.sql.ResultSet rs = pst.executeQuery();
                boolean f=false;
                while (rs.next()) {
                    f=true;
                    zz.setUser_pwd(rs.getString(1));
                }
                if (f==false) {
                    throw new BaseException("用户不存在");
                }
                if (!pwd.equals(zz.getUser_pwd())) {
                    throw new BaseException("密码错误");
                }
                rs.close();
                pst.close();
                return zz;
            }
            catch (SQLException e){
                e.printStackTrace();
                throw new DbException(e);
            }
            finally {
                if (conn != null) 
                    try {
                        conn.close();
                    }
                catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            //return null;
        }
    
    
        @Override
        public void changePwd(BeanUser user, String oldPwd, String newPwd,
                String newPwd2) throws BaseException {
            // TODO Auto-generated method stub
            Connection conn = null;
            try {
                conn = DBUtil.getConnection();
                String sql = "update tbl_user set user_pwd = '"+newPwd+"' where user_id = '"+user.getUser_id()+"'";
                System.out.println(sql);
                java.sql.Statement st = conn.createStatement();
                st.execute(sql);
            }
            catch (SQLException e){
                e.printStackTrace();
                throw new DbException(e);
            }
            finally {
                if (conn != null) 
                    try {
                        conn.close();
                    }
                catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
    }
  • 相关阅读:
    C# 依赖注入中的 控制反转(Assembly)实现
    C# 依赖注入中的 控制反转(Assembly)实现
    Asp.net web form 动态生成控件的注意事项
    jackson的转换object转map
    SpringCloud+Feign+Hystrix使用FallbackFactory统一处理,查看服务调用异常或失败,进入熔断降级处理的原因
    feign调用返回object类型转换成实体
    Springboot @ResponseBody返回中文乱码
    Feign 传参问题及传输Date类型参数的时差 坑
    Mybatis plus条件构造器QueryWrapper的简单用法
    Java命令里面的EQ、NE、GT、LT、GE、LE分别代表含义
  • 原文地址:https://www.cnblogs.com/zhanglichen/p/13219304.html
Copyright © 2020-2023  润新知