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;
}
}
网友评论