美文网首页
UserInfoService.class

UserInfoService.class

作者: 张威先森 | 来源:发表于2018-10-16 18:05 被阅读0次

    package com.model.service;

    import java.sql.Connection;
    import java.sql.SQLException;

    import com.model.bean.UserInfo;
    import com.model.dao.AddUserDaoImp;

    import utils.DBUtil;

    public class UserInfoService {
    private static UserInfoService instance=new UserInfoService();

    private UserInfoService(){}
    
    public static UserInfoService getInstance(){
        return instance;
    }
    
    public  void saveUser(UserInfo user) throws Exception{
        
        Connection conn=DBUtil.getConnection();
        conn.setAutoCommit(false);
        try{
            AddUserDaoImp dao=new AddUserDaoImp(conn);
            dao.saveUser(user);
            conn.commit();
        }catch(Exception e){
            conn.rollback();
        }finally{
            conn.close();
        }
    
    }
    
    //校验用户名是否重复
    public boolean valiadateUsername(UserInfo user) throws SQLException{
        Connection conn=DBUtil.getConnection();
        AddUserDaoImp dao=new AddUserDaoImp(conn);
        boolean flag=dao.validateUsername(user);
        DBUtil.closeConn(conn);
        return flag;
        
    }
    

    }

    相关文章

      网友评论

          本文标题:UserInfoService.class

          本文链接:https://www.haomeiwen.com/subject/ioahzftx.html