package com.skic.service;

import java.sql.*;

import com.skic.DAO.UserDAO;
import com.skic.DAO.impl.UserDAOimpl;
import com.skic.DTO.UserDTO;
import com.skic.util.ConnectionFactory;

public class CheckNameService {
	private UserDAO userdao = new UserDAOimpl();

	public boolean CheckName(UserDTO USERDTO) {
		Connection conn = null;
		try {
			conn = ConnectionFactory.getInstance().makeConnection();
			conn.setAutoCommit(false);
			ResultSet resultSet1 = userdao.checkUserNameExist(conn, USERDTO);//调用数据库查询
			conn.commit();
			if (resultSet1.next()) {//查询用户名是否存在
				return true;//存在则返回true
			}
		} catch (SQLException e) {
			System.out.println("获取查询结果失败");
			e.printStackTrace();
			try {
				System.out.println("更新数据失败，数据库回滚");
				conn.rollback();
			} catch (SQLException e1) {
				System.out.println("数据库回滚失败");
				e1.printStackTrace();
			}
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					System.out.println("数据库关闭失败");
					e.printStackTrace();
				}
			}
		}

		return false;
	}
}
