package idc.main.command;

import idc.model.IdcCmd;
import idc.model.IdcDAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class IdcMemberDeleteCmd implements IdcCmd
{
	private IdcDAO dao;
	public IdcMemberDeleteCmd()
	{
		dao = new IdcDAO();
	}
	
	//회원탈퇴.
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
	{
		delMember(request.getParameter("mem_id"));
	}
	private void delMember(String id)
	{
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		String sql="";
		try	
		{
			conn=dao.getConn();
			sql="DELETE FROM memberdb WHERE id=?";
			pstmt =conn.prepareStatement(sql);
			pstmt.setString(1, id);
			pstmt.executeUpdate();
		}
		catch (Exception e) 
		{
			System.out.println("IdcMemberDeleteCmd 에서의 exception");
			e.printStackTrace();
		}
		finally
		{
			try 
			{
				if(conn!=null) conn.close();
				if(pstmt!=null)pstmt.close();
				if(rs!=null)rs.close();
			}
			catch (SQLException e) 
			{
				System.out.println("IdcMemberDeleteCmd 에서의 sqlexception");
				e.printStackTrace();
			}
		}
	}
}
