zoukankan      html  css  js  c++  java
  • 用户界面的代码

    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();
                }
            }
        }
    
    }
  • 相关阅读:
    【转】海量数据处理算法-Bloom Filter
    【c++】【转】结构体字节对齐
    【APUE】信号量、互斥体和自旋锁
    【python】Python的字典get方法:从字典中获取一个值
    【python】Python中*args 和**kwargs的用法
    【python】super()
    【algorithm】尾递归
    什么时候必须使用初始化列表
    【APUE】wait与waitpid函数
    【APUE】孤儿进程与僵死进程
  • 原文地址:https://www.cnblogs.com/zhanglichen/p/13219304.html
Copyright © 2011-2022 走看看