package idc.line.command;

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;

import idc.model.*;

public class IdcIPDeleteHandleCmd implements IdcCmd{

	IdcDAO dao = new IdcDAO();
	
	//ip지우기
	public void execute(HttpServletRequest request, HttpServletResponse response){
		
		String ip_address = request.getParameter("ip_address");
		String line_code = request.getParameter("line_code");
		
		request.setAttribute("lineCode", line_code);
		
		ipDelete(ip_address);
	}
	
	public void ipDelete(String ip_address)
	{
		Connection conn = null;
		PreparedStatement pstmt = null;
		
		try {
			conn = dao.getConn();
			
			String sql = "DELETE FROM ipdb WHERE ip_address=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, ip_address);
			
			pstmt.executeUpdate();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			try {
				if(pstmt != null) pstmt.close();
				if(conn != null) conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
