AddUserService
2018-10-15 本文已影响0人
张威先森
package com.model.service;
import java.sql.Connection;
import java.sql.SQLException;
import com.model.bean.UserInfo;
import com.model.dao.AddUserDAOImp;
import com.model.dao.AddUserDao;
import utils.DBUtil;
public class AddUserService {
private static AddUserService instance=new AddUserService();
public static AddUserService getInstance(){
return instance;
}
private AddUserService(){
}
//保护用户信息
public static void saveUser(UserInfo user) throws SQLException{
//获取连接对象
Connection conn=DBUtil.getConnection();
//开启事务 即关闭自动提交 防止出现脏数据
conn.setAutoCommit(false);
//做异常处理
try {
AddUserDao dao=new AddUserDAOImp(conn);
dao.saveUser(user);
conn.commit();
} catch (Exception e) {
conn.rollback();
}finally{
DBUtil.closeConn(conn);
}
}
}