package utility;

import idc.model.IdcDAO;

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

public class IdcSetCS
{
	//CS DB입력
	public static void setCS(String service_code, String server_code, String cs_name)
	{
		IdcDAO dao = new IdcDAO();
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		
		try	
		{
			conn=dao.getConn();
			String sql="INSERT INTO csdb(service_code, server_code, cs_name) ";
			sql+="values(?,?,?)";
			pstmt =conn.prepareStatement(sql);
			pstmt.setString(1, service_code);
			pstmt.setString(2, server_code);
			pstmt.setString(3, cs_name);
			pstmt.executeUpdate();
		}
		catch (Exception e) 
		{
			System.out.println("IdcSetCS - setCS  에서의 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("IdcSetCS - setCS 에서의 sqlexception");
				e.printStackTrace();
			}
		}
	}
	
	public static void modifyCS(String cs_name, String cs_case)
	{
		IdcDAO dao = new IdcDAO();
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try	
		{
			conn=dao.getConn();
			String sql="UPDATE csdb SET cs_case=? WHERE cs_name=?";
			pstmt =conn.prepareStatement(sql);
			pstmt.setString(1, cs_case);
			pstmt.setString(2, cs_name);
			pstmt.executeUpdate();
			
		}
		catch (Exception e) 
		{
			System.out.println("IdcSetCS - modifyCS  에서의 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("IdcSetCS - modifyCS  에서의 sqlexception");
				e.printStackTrace();
			}
		}
	}
	
	public static void deleteCS(String cs_name)
	{
		IdcDAO dao = new IdcDAO();
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try	
		{
			conn=dao.getConn();
			String sql="DELETE FROM csdb WHERE cs_name=?";
			pstmt =conn.prepareStatement(sql);
			pstmt.setString(1, cs_name);
			pstmt.executeUpdate();
		}
		catch (Exception e) 
		{
			System.out.println("IdcSetCS - deleteCS  에서의 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("IdcSetCS - deleteCS  에서의 sqlexception");
				e.printStackTrace();
			}
		}
	}
}
