package utility;

import idc.model.IdcDAO;

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


public class IdcGetClientNameCode
{
	public static String getClientName(String client_code){

		IdcDAO dao = new IdcDAO();
		String client_name=null;
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try{
			conn=dao.getConn();
			String sql="SELECT client_name FROM clientdb WHERE client_code=?";
			pstmt =conn.prepareStatement(sql);
			pstmt.setString(1, client_code);
			rs=pstmt.executeQuery();
			if(rs.next())
				client_name = rs.getString("client_name");

		}
		catch (Exception e) 
		{
			System.out.println("getClientName 에서의 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("getClientName 에서의 sqlexception");
				e.printStackTrace();
			}
		}
		return client_name;
	}
	
	//client_name -->client_code
	public static String getClientCode(String client_name)
	{
		IdcDAO dao = new IdcDAO();
		String client_code=null;
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;

		try	
		{
			conn=dao.getConn();
			String sql="SELECT client_code FROM clientdb WHERE client_name=?";
			pstmt =conn.prepareStatement(sql);
			pstmt.setString(1, client_name);
			rs=pstmt.executeQuery();
			if(rs.next())
			{
				client_code = rs.getString("client_code");
			}
			
		}
		catch (Exception e) 
		{
			System.out.println("getClientCode 에서의 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("getClientCode 에서의 sqlexception");
				e.printStackTrace();
			}
		}
		return client_code;
	}
}
