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();
                }
            }
        }
    
    }
  • 相关阅读:
    poj 2002 Squares 几何二分 || 哈希
    hdu 1969 Pie
    hdu 4004 The Frog's Games 二分
    hdu 4190 Distributing Ballot Boxes 二分
    hdu 2141 Can you find it? 二分
    Codeforces Round #259 (Div. 2)
    并查集
    bfs
    二维树状数组
    一维树状数组
  • 原文地址:https://www.cnblogs.com/zhanglichen/p/13219304.html
Copyright © 2011-2022 走看看