/* 
    IntraPMS Project
    조직도 관리 DBManager

    
*/
import java.sql.* ;

import com.etri.groupware.*;
import com.etri.groupware.organization.*;

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import sun.misc.*;
import java.util.*;

public class PandaSoftOrganizationDBManager implements OrganizationDBManagerInterface {
	
	// DBConnectionPool을 사용하기 위한 전역 변수들.....
	static DBConnectionManager connectionManager = null ;
	int servletInits = 0 ;
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: init<br>
	 [기능]: DBConnectionManager를 가져온다.<br>
	 [파라미터]: 없음<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */  	
	public void init(){
		connectionManager = DBConnectionManager.getInstance();
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: searchDepartment<br>
	 [기능]: 부서 검색 조건을 넘겨 받아서 부서를 검색한 후 부서 검색 결과를 리턴한다. <br>
	 [파라미터]: DepartmentSearchProperty dsp<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
  	public Department[] searchDepartment ( DepartmentSearchProperty dsp ) {
		// 커넥션 풀을 이용하여 데이타 베이스와 연결하고 스테이트먼트까지 알아 낸다.

		
		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			// 검색 조건을 알아내서 쿼리를 검색 조건에 맞게 던진다.
			String searchN = dsp.getName ( ) ;
			String searchWW = dsp.getWeightWork ( ) ; 
			String searchDE = dsp.getDepartmentExplain ( ) ;
			
			ResultSet rslt ;
			// 부서의 숫자를 알아낸다.
			if ( dsp.getOrOrAnd() ) {
				boolean first = true ;
				String tmpQ = "SELECT COUNT(*) AS OUTPUT FROM Department WHERE " ;
				if ( !(searchN.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "name LIKE \'%" + searchN + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "name LIKE \'%" + searchN + "%\'" ;
					}
				}															
				if ( !(searchWW.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "weightWork LIKE \'%" + searchWW + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "weightWork LIKE \'%" + searchWW + "%\'" ;
					}
				}
				if ( !(searchDE.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "departmentExplain LIKE \'%" + searchDE + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "departmentExplain LIKE \'%" + searchDE + "%\'" ;
					}
				}														
				System.out.println ( "OR로 검색하고, 쿼리 문장은" + tmpQ + "입니다." ) ;
				rslt = stmt.executeQuery ( tmpQ ) ;
			} else { 
				String tmpO = "SELECT COUNT(*) AS OUTPUT FROM Department WHERE " 
																			+ "name LIKE \'%" + searchN + "%\'"
																			+ " and " + "weightWork LIKE \'%" + searchWW + "%\'"
																			+ " and " + "departmentExplain LIKE \'%" + searchDE + "%\'" ;
				System.out.println ( "AND로 검색하고, 쿼리 문장은" + tmpO + "입니다." ) ;
				rslt = stmt.executeQuery( tmpO ) ;
			}
				
			rslt.next ( ) ;
			int depNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "부서의 갯수를 알아냈습니다." + depNum + "개 입니다." ) ;
						
			Department[] allDep = new Department[depNum+2] ;
			int index = 0 ;
			
			// 부서를 가져온다.
			if ( dsp.getOrOrAnd() ) {
				boolean first = true ;
				String tmpQ = "SELECT * FROM Department WHERE " ;
				if ( !(searchN.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "name LIKE \'%" + searchN + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "name LIKE \'%" + searchN + "%\'" ;
					}
				}															
				if ( !(searchWW.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "weightWork LIKE \'%" + searchWW + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "weightWork LIKE \'%" + searchWW + "%\'" ;
					}
				}
				if ( !(searchDE.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "departmentExplain LIKE \'%" + searchDE + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "departmentExplain LIKE \'%" + searchDE + "%\'" ;
					}
				}														
				System.out.println ( "OR로 검색하고, 쿼리 문장은" + tmpQ + "입니다." ) ;
				rslt = stmt.executeQuery ( tmpQ ) ;
			} else { 
				String tmpO = "SELECT * FROM Department WHERE " 
																			+ "name LIKE \'%" + searchN + "%\'"
																			+ " and " + "weightWork LIKE \'%" + searchWW + "%\'"
																			+ " and " + "departmentExplain LIKE \'%" + searchDE + "%\'" ;
				rslt = stmt.executeQuery( tmpO ) ;
			}
									
			while ( rslt.next ( ) ) {
				Department tempDep = new Department ( ) ;
				tempDep.setName ( rslt.getString ( "name" ) ) ;
				tempDep.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempDep.setPhoneNumber ( rslt.getString ( "phoneNumber" ) ) ;
				tempDep.setFaxNumber ( rslt.getString ( "faxNumber" ) ) ;
				tempDep.setWebURL ( rslt.getString ( "webURL" ) ) ;
				tempDep.setDepartmentExplain ( rslt.getString ( "departmentExplain" ) ) ;
				allDep[index++] = tempDep ;				
			}
			allDep[index] = new Department ( ) ;
			allDep[index].setName ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allDep ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			
			Department[] allDep = new Department [ 1 ] ;
			Department error = new Department ( ) ;
			error.setName ( "error" ) ;
			error.setWeightWork ( e.toString ( ) ) ;
			allDep[0] = error ;
			
			return allDep ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: addDepartment<br>
	 [기능]: 새로운 부서를 생성한다. <br>
	 [파라미터]: Department d<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus addDepartment ( Department d ) {

		
		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			// transaction처리를 위해서 autoCommit을 false로 만든다.
			con.setAutoCommit ( false ) ;
			
			// insert SQL 문장을 만들어서 실행한다.
			String iSQL = "insert into Department values ( \'" 
							+ d.getName() + "\',\'" 
							+ d.getWeightWork() + "\',\'" 
							+ d.getPhoneNumber() + "\',\'" 
							+ d.getFaxNumber() + "\',\'" 
							+ d.getWebURL() + "\',\'" 
							+ d.getDepartmentExplain() + "\')" ;
			System.out.println ( "만들어진 쿼리는" + iSQL ) ;
			stmt.executeUpdate ( iSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			OrganizationResultStatus ors = new OrganizationResultStatus ( 0 ) ;
			
			con.commit ( ) ;
			
			return ors ;
		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			} 
				
			System.out.println ( e.toString ( ) ) ;
			OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
			ors.setReason ( e.toString ( ) ) ;
			return ors ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
					
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: updateDepartment<br>
	 [기능]: 존재하는 부서를 변경한다. <br>
	 [파라미터]: Department d<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus updateDepartment ( Department d ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			// update SQL 문장을 만들어서 실행한다.
			String uSQL = "update Department set weightWork=\'" 
						+ d.getWeightWork() + "\',phoneNumber=\'" 
						+ d.getPhoneNumber() + "\',faxNumber=\'" 
						+ d.getFaxNumber() + "\',webURL=\'" 
						+ d.getWebURL() + "\',departmentExplain=\'" 
						+ d.getDepartmentExplain() + "\' where name=\'" 
						+ d.getName() + "\'" ;
			System.out.println ( "만들어진 쿼리는" + uSQL ) ;
			stmt.executeUpdate ( uSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			con.commit ( ) ;
			
			return new OrganizationResultStatus ( ) ;
			
		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: deleteDepartment<br>
	 [기능]: 존재하는 부서를 삭제한다. <br>
	 [파라미터]: Department d<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus deleteDepartment ( Department d ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			/////////////////////
			System.out.println ( "DB매니저가 받은 내용" + "/" + d.getName() + "/" ) ;
			
			// delete SQL 문장을 만들어서 실행한다.
			String dSQL = "delete from Department where name=\'" + d.getName() + "\'" ;
			System.out.println ( "만들어진 쿼리는" + dSQL ) ;
			stmt.executeUpdate ( dSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			con.commit ( ) ;
			
			return new OrganizationResultStatus ( ) ;

		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: getAllDepartment<br>
	 [기능]: 존재하는 모든 부서를 리턴한다. <br>
	 [파라미터]: 없음<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public Department[] getAllDepartment ( ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;

			// 부서의 숫자를 알아낸다.
			ResultSet rslt = stmt.executeQuery( "SELECT COUNT(*) AS OUTPUT FROM Department" ) ;
			rslt.next ( ) ;
			int depNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "부서의 갯수를 알아냈습니다." + depNum + "개 입니다." ) ;
						
			Department[] allDep = new Department[depNum+2] ;
			int index = 0 ;
			
			// 부서를 가져온다.
			rslt = stmt.executeQuery ( "SELECT * FROM Department" ) ;
						
			while ( rslt.next ( ) ) {
				Department tempDep = new Department ( ) ;
				tempDep.setName ( rslt.getString ( "name" ) ) ;
				tempDep.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempDep.setPhoneNumber ( rslt.getString ( "phoneNumber" ) ) ;
				tempDep.setFaxNumber ( rslt.getString ( "faxNumber" ) ) ;
				tempDep.setWebURL ( rslt.getString ( "webURL" ) ) ;
				tempDep.setDepartmentExplain ( rslt.getString ( "departmentExplain" ) ) ;
				allDep[index++] = tempDep ;				
			}
			allDep[index] = new Department ( ) ;
			allDep[index].setName ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allDep ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			
			Department[] allDep = new Department [ 1 ] ;
			Department error = new Department ( ) ;
			error.setName ( "error" ) ;
			error.setWeightWork ( e.toString ( ) ) ;
			allDep[0] = error ;
			
			return allDep ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: searchTeam<br>
	 [기능]: 검색 조건을 만족하는 팀을 검색한다. <br>
	 [파라미터]: TeamSearchProperty tsp<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public Team[] searchTeam ( TeamSearchProperty tsp ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			// 검색 조건을 알아내서 쿼리를 검색 조건에 맞게 던진다.
			String searchN = tsp.getName ( ) ;
			String searchUD = tsp.getUpDepartment ( ) ;
			String searchWW = tsp.getWeightWork ( ) ; 
			String searchDF = tsp.getDevelopField ( ) ;
			String searchTE = tsp.getTeamExplain ( ) ;
			
			ResultSet rslt ;
			// 팀의 숫자를 알아낸다.
			if ( tsp.getOrOrAnd() ) {
				boolean first = true ;
				String tmpQ = "SELECT COUNT(*) AS OUTPUT FROM Team WHERE " ;
				if ( !(searchN.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "name LIKE \'%" + searchN + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "name LIKE \'%" + searchN + "%\'" ;
					}
				}															
				if ( !(searchUD.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "upDepartment LIKE \'%" + searchUD + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "upDepartment LIKE \'%" + searchUD + "%\'" ;
					}
				}					
				if ( !(searchWW.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "weightWork LIKE \'%" + searchWW + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "weightWork LIKE \'%" + searchWW + "%\'" ;
					}
				}
				if ( !(searchDF.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "developField LIKE \'%" + searchDF + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "developField LIKE \'%" + searchDF + "%\'" ;
					}
				}	
				if ( !(searchTE.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "teamExplain LIKE \'%" + searchTE + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "teamExplain LIKE \'%" + searchTE + "%\'" ;
					}
				}														
				System.out.println ( "OR로 검색하고, 쿼리 문장은" + tmpQ + "입니다." ) ;
				rslt = stmt.executeQuery ( tmpQ ) ;
			} else { 
				String tmpO = "SELECT COUNT(*) AS OUTPUT FROM Team WHERE " 
									+ "name LIKE \'%" + searchN + "%\'"
									+ " and " + "upDepartment LIKE \'%" + searchUD + "%\'"
									+ " and " + "weightWork LIKE \'%" + searchWW + "%\'"
									+ " and " + "developField LIKE \'%" + searchDF + "%\'"
									+ " and " + "teamExplain LIKE \'%" + searchTE + "%\'" ;
				System.out.println ( "AND로 검색하고, 쿼리 문장은" + tmpO + "입니다." ) ;
				rslt = stmt.executeQuery( tmpO ) ;
			}
				
			rslt.next ( ) ;
			int teamNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "팀의 갯수를 알아냈습니다." + teamNum + "개 입니다." ) ;
						
			Team[] allTeam = new Team[teamNum+2] ;
			int index = 0 ;
			
			// 팀을 가져온다.
			if ( tsp.getOrOrAnd() ) {
				boolean first = true ;
				String tmpQ = "SELECT * FROM Team WHERE " ;
				if ( !(searchN.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "name LIKE \'%" + searchN + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "name LIKE \'%" + searchN + "%\'" ;
					}
				}															
				if ( !(searchUD.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "upDepartment LIKE \'%" + searchUD + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "upDepartment LIKE \'%" + searchUD + "%\'" ;
					}
				}					
				if ( !(searchWW.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "weightWork LIKE \'%" + searchWW + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "weightWork LIKE \'%" + searchWW + "%\'" ;
					}
				}
				if ( !(searchDF.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "developField LIKE \'%" + searchDF + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "developField LIKE \'%" + searchDF + "%\'" ;
					}
				}	
				if ( !(searchTE.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "teamExplain LIKE \'%" + searchTE + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "teamExplain LIKE \'%" + searchTE + "%\'" ;
					}
				}														
				System.out.println ( "OR로 검색하고, 쿼리 문장은" + tmpQ + "입니다." ) ;
				rslt = stmt.executeQuery ( tmpQ ) ;
			} else { 
				String tmpO = "SELECT * FROM Team WHERE " 
								+ "name LIKE \'%" + searchN + "%\'"
								+ " and " + "upDepartment LIKE \'%" + searchUD + "%\'"
								+ " and " + "weightWork LIKE \'%" + searchWW + "%\'"
								+ " and " + "developField LIKE \'%" + searchDF + "%\'"
								+ " and " + "teamExplain LIKE \'%" + searchTE + "%\'" ;
				System.out.println ( "AND로 검색하고, 쿼리 문장은" + tmpO + "입니다." ) ;
				rslt = stmt.executeQuery( tmpO ) ;
			} 									
			while ( rslt.next ( ) ) {
				Team tempTeam = new Team ( ) ;
				tempTeam.setName ( rslt.getString ( "name" ) ) ;
				tempTeam.setUpDepartment ( rslt.getString ( "upDepartment" ) ) ;
				tempTeam.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempTeam.setWebURL ( rslt.getString ( "webURL" ) ) ;
				tempTeam.setDevelopField ( rslt.getString ( "developField" ) ) ;
				tempTeam.setTeamExplain ( rslt.getString ( "teamExplain" ) ) ;
				allTeam[index++] = tempTeam ;				
			}
			allTeam[index] = new Team ( ) ;
			allTeam[index].setName ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allTeam ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			
			Team[] allTeam = new Team [ 1 ] ;
			Team error = new Team ( ) ;
			error.setName ( "error" ) ;
			error.setWeightWork ( e.toString ( ) ) ;
			allTeam[0] = error ;
			
			return allTeam ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: addTeam<br>
	 [기능]: 새로운 팀을 생성한다. <br>
	 [파라미터]: Team t<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus addTeam ( Team t ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			// insert SQL 문장을 만들어서 실행한다.
			String iSQL = "insert into Team values ( \'" 
							+ t.getName() + "\',\'" 
							+ t.getUpDepartment() + "\',\'" 
							+ t.getWeightWork() + "\',\'" 
							+ t.getWebURL() + "\',\'" 
							+ t.getDevelopField() + "\',\'" 
							+ t.getTeamExplain() + "\')" ;
			System.out.println ( "만들어진 쿼리는" + iSQL ) ;
			stmt.executeUpdate ( iSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			OrganizationResultStatus ors = new OrganizationResultStatus ( 0 ) ;
			
			con.commit () ;
			
			return ors ;
		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
			ors.setReason ( e.toString ( ) ) ;
			return ors ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: updateTeam<br>
	 [기능]: 팀의 정보를 변경한다. <br>
	 [파라미터]: Team t<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus updateTeam ( Team t ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");  
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			// update SQL 문장을 만들어서 실행한다.
			String uSQL = "update Team set weightWork=\'" 
							+ t.getWeightWork() + "\',webURL=\'" 
							+ t.getWebURL() + "\',developField=\'" 
							+ t.getDevelopField() + "\',teamExplain=\'" 
							+ t.getTeamExplain() + "\' where name=\'" 
							+ t.getName() + "\' and upDepartment=\'" 
							+ t.getUpDepartment() + "\'" ;
			System.out.println ( "만들어진 쿼리는" + uSQL ) ;
			stmt.executeUpdate ( uSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			con.commit ( ) ;
			
			return new OrganizationResultStatus ( ) ;

		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: deleteTeam<br>
	 [기능]: 팀을 삭제한다. <br>
	 [파라미터]: Team t<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus deleteTeam ( Team t ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			/////////////////////
			System.out.println ( "DB매니저가 받은 내용" + "/" + t.getName() + "/" ) ;
			
			// delete SQL 문장을 만들어서 실행한다.
			String dSQL = "delete from Team where name=\'" 
							+ t.getName() + "\' and upDepartment=\'" 
							+ t.getUpDepartment() + "\'" ;
			System.out.println ( "만들어진 쿼리는" + dSQL ) ;
			stmt.executeUpdate ( dSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			con.commit ( ) ;
			
			return new OrganizationResultStatus ( ) ;
			
		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: getAllTeam<br>
	 [기능]: 부서에 존재하는 모든 팀을 리턴한다. <br>
	 [파라미터]: Department d<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public Team[] getAllTeam ( Department d ) {

		// 부서의 이름을 알아내자...
		String upDepName = d.getName ( ) ;
		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			ResultSet rslt = stmt.executeQuery( "SELECT COUNT(*) AS OUTPUT FROM Team WHERE upDepartment=\'" + upDepName + "\'"  ) ;
			rslt.next ( ) ;
			int teamNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "팀의 갯수를 알아냈습니다." + teamNum + "개 입니다." ) ;
						
			Team[] allTeam = new Team[teamNum+2] ;
			int index = 0 ;
			
			// 팀를 가져온다.
			rslt = stmt.executeQuery ( "SELECT * FROM Team WHERE upDepartment=\'" + upDepName + "\'"  ) ;
						
			while ( rslt.next ( ) ) {
				Team tempTeam = new Team ( ) ;
				tempTeam.setName ( rslt.getString ( "name" ) ) ;
				tempTeam.setUpDepartment ( rslt.getString ( "upDepartment" ) ) ;
				tempTeam.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempTeam.setWebURL ( rslt.getString ( "webURL" ) ) ;
				tempTeam.setDevelopField ( rslt.getString ( "developField" ) ) ;
				tempTeam.setTeamExplain ( rslt.getString ( "teamExplain" ) ) ;
				allTeam[index++] = tempTeam ;				
			}
			allTeam[index] = new Team ( ) ;
			allTeam[index].setName ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allTeam ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: searchOfficial<br>
	 [기능]: 검색 조건을 만족하는 사원을 검색한다. <br>
	 [파라미터]: OfficialSearchProperty osp<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public Official[] searchOfficial ( OfficialSearchProperty osp ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			// 검색 조건을 알아내서 쿼리를 검색 조건에 맞게 던진다.
			String searchN = osp.getName ( ) ;
			String searchWW = osp.getWeightWork ( ) ; 
			Calendar cal = osp.getEnterCompanyDay() ;
			String enterCompanyDay = null ;
			if ( osp.getIsECD() ) {
				System.out.println ( "입사일 검색이 체크 되어 있습니다." ) ;
				enterCompanyDay = cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DATE) + "/" + cal.get(Calendar.YEAR) ;
			} 
			String searchA = osp.getAddress ( ) ;
			int sex = 0 ;
			if ( osp.getIsSEX() ) {
				System.out.println ( "성별 검색이 체크 되어 있습니다." ) ;
				if ( osp.getSex() ) sex = 1 ;
				if ( osp.getSex() == false ) sex = 2 ;
			}
			String searchOD = osp.getOrders ( ) ;
			String searchOT = osp.getOthers ( ) ;
			String searchID = osp.getId ( ) ;
			
			ResultSet rslt ;
			// 사원의 숫자를 알아낸다.
			if ( osp.getOrOrAnd() ) {
				boolean first = true ;
				String tmpQ = "SELECT COUNT(*) AS OUTPUT FROM Official WHERE " ;
				if ( !(searchN.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "firstName LIKE \'%" + searchN + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "firstName LIKE \'%" + searchN + "%\'" ;
					}
				}															
				if ( !(searchWW.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "weightWork LIKE \'%" + searchWW + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "weightWork LIKE \'%" + searchWW + "%\'" ;
					}
				}
				if ( osp.getIsECD() ) {
					if ( first ) {
						if ( osp.getBeforeOrAfter() ) {
							tmpQ = tmpQ + "enterCompanyDay <= \'" + enterCompanyDay + "\'" ;
						} else {
							tmpQ = tmpQ + "enterCompanyDay >= \'" + enterCompanyDay + "\'" ;
						}							
						first = false ;
					} else {
						if ( osp.getBeforeOrAfter() ) {
							tmpQ = tmpQ + " or " + "enterCompanyDay <= \'" + enterCompanyDay + "\'" ;
						} else {
							tmpQ = tmpQ + " or " + "enterCompanyDay >= \'" + enterCompanyDay + "\'" ;
						}
					}
				}	
				if ( !(searchA.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "address LIKE \'%" + searchA + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "address LIKE \'%" + searchA + "%\'" ;
					}
				}														
				if ( osp.getIsSEX() ) {
					if ( first ) {
						tmpQ = tmpQ + "sex = " + sex ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "sex = " + sex ;
					}
				}
				if ( !(searchOD.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "orders LIKE \'%" + searchOD + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "orders LIKE \'%" + searchOD + "%\'" ;
					}
				}
				if ( !(searchOT.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "others LIKE \'%" + searchOT + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "others LIKE \'%" + searchOT + "%\'" ;
					}
				}
				if ( !(searchID.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "id LIKE \'%" + searchID + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "id LIKE \'%" + searchID + "%\'" ;
					}
				}
				System.out.println ( "OR로 검색하고, 쿼리 문장은" + tmpQ + "입니다." ) ;
				rslt = stmt.executeQuery ( tmpQ ) ;
			} else { 
				String tmpO = "SELECT COUNT(*) AS OUTPUT FROM Official WHERE " 
																			+ "firstName LIKE \'%" + searchN + "%\'"
																			+ " and " + "weightWork LIKE \'%" + searchWW + "%\'"
																			+ " and " + "address LIKE \'%" + searchA + "%\'"
																			+ " and " + "sex =" + sex 
																			+ " and " + "orders LIKE \'%" + searchOD + "%\'"
																			+ " and " + "others LIKE \'%" + searchOT + "%\'" 
																			+ " and " + "id LIKE \'%" + searchID + "%\'" ;
				if ( osp.getIsECD() ) {
					if ( osp.getBeforeOrAfter() ) tmpO = tmpO + " and " + "enterCompanyDay <= \'" + enterCompanyDay + "\'" ;
					else tmpO = tmpO + " and " + "enterCompanyDay >= \'" + enterCompanyDay + "\'" ;
				}
				System.out.println ( "AND로 검색하고, 쿼리 문장은" + tmpO + "입니다." ) ;
				rslt = stmt.executeQuery( tmpO ) ;
			}
				
			rslt.next ( ) ;
			int officialNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "사원의 수를 알아냈습니다." + officialNum + "개 입니다." ) ;
						
			Official[] allOfficial = new Official[officialNum+2] ;
			int index = 0 ;
			
			// 사원을 가져온다.
			if ( osp.getOrOrAnd() ) {
				boolean first = true ;
				String tmpQ = "SELECT * FROM Official WHERE " ;
				if ( !(searchN.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "firstName LIKE \'%" + searchN + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "firstName LIKE \'%" + searchN + "%\'" ;
					}
				}															
				if ( !(searchWW.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "weightWork LIKE \'%" + searchWW + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "weightWork LIKE \'%" + searchWW + "%\'" ;
					}
				}
				if ( osp.getIsECD() ) {
					if ( first ) {
						if ( osp.getBeforeOrAfter() ) {
							tmpQ = tmpQ + "enterCompanyDay <= \'" + enterCompanyDay + "\'" ;
						} else {
							tmpQ = tmpQ + "enterCompanyDay >= \'" + enterCompanyDay + "\'" ;
						}							
						first = false ;
					} else {
						if ( osp.getBeforeOrAfter() ) {
							tmpQ = tmpQ + " or " + "enterCompanyDay <= \'" + enterCompanyDay + "\'" ;
						} else {
							tmpQ = tmpQ + " or " + "enterCompanyDay >= \'" + enterCompanyDay + "\'" ;
						}
					}
				}	
				if ( !(searchA.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "address LIKE \'%" + searchA + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "address LIKE \'%" + searchA + "%\'" ;
					}
				}														
				if ( osp.getIsSEX() ) {
					if ( first ) {
						tmpQ = tmpQ + "sex = " + sex ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "sex = " + sex ;
					}
				}
				if ( !(searchOD.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "orders LIKE \'%" + searchOD + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "orders LIKE \'%" + searchOD + "%\'" ;
					}
				}
				if ( !(searchOT.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "others LIKE \'%" + searchOT + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "others LIKE \'%" + searchOT + "%\'" ;
					}
				}
				if ( !(searchID.equals("")) ) {
					if ( first ) {
						tmpQ = tmpQ + "id LIKE \'%" + searchID + "%\'" ;
						first = false ;
					} else {
						tmpQ = tmpQ + " or " + "id LIKE \'%" + searchID + "%\'" ;
					}
				}
				System.out.println ( "OR로 검색하고, 쿼리 문장은" + tmpQ + "입니다." ) ;
				rslt = stmt.executeQuery ( tmpQ ) ;
			} else { 
				String tmpO = "SELECT * FROM Official WHERE " 
								+ "firstName LIKE \'%" + searchN + "%\'"
								+ " and " + "weightWork LIKE \'%" + searchWW + "%\'"
								+ " and " + "address LIKE \'%" + searchA + "%\'"
								+ " and " + "sex =" + sex 
								+ " and " + "orders LIKE \'%" + searchOD + "%\'"
								+ " and " + "others LIKE \'%" + searchOT + "%\'" 
								+ " and " + "id LIKE \'%" + searchID + "%\'" ;
				if ( osp.getIsECD() ) {
					if ( osp.getBeforeOrAfter() ) tmpO = tmpO + " and " + "enterCompanyDay <= \'" + enterCompanyDay + "\'" ;
					else tmpO = tmpO + " and " + "enterCompanyDay >= \'" + enterCompanyDay + "\'" ;
				}
				System.out.println ( "AND로 검색하고, 쿼리 문장은" + tmpO + "입니다." ) ;
				rslt = stmt.executeQuery( tmpO ) ;
			}
			while ( rslt.next ( ) ) {
				Official tempOfficial = new Official ( ) ;
				tempOfficial.setId ( rslt.getString ( "id" ) ) ;
				tempOfficial.setPassword ( rslt.getString ( "password" ) ) ;
				tempOfficial.setResidentRegistrationNum ( rslt.getString ( "residentRegistrationNum" ) ) ;
				tempOfficial.setFirstName ( rslt.getString ( "firstName" ) ) ;
				tempOfficial.setFamilyName ( rslt.getString ( "FamilyName" ) ) ;
				if ( rslt.getString ( "sex" ).equals( "1" ) ) {
					tempOfficial.setSex ( true )  ;
				} else {
					tempOfficial.setSex ( false ) ;
				}
				tempOfficial.setAge ( Integer.parseInt( rslt.getString ( "age" ) ) ) ;
				tempOfficial.setAddress ( rslt.getString ( "address" ) ) ;
				tempOfficial.setZipCode ( rslt.getString ( "zipCode" ) ) ;
				tempOfficial.setPhoneNumber ( rslt.getString ( "phoneNumber" ) ) ;
				tempOfficial.setEmail ( rslt.getString ( "email" ) ) ;										
				tempOfficial.setPersonalPhone ( rslt.getString ( "personalPhone" ) ) ;
				tempOfficial.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempOfficial.setDepartment ( rslt.getString ( "department" ) ) ;
				tempOfficial.setTeam ( rslt.getString ( "team" ) ) ;
				tempOfficial.setOrders ( rslt.getString ( "orders" ) ) ;
				String tempCal = rslt.getString ( "enterCompanyDay" ) ;
				Calendar enterCompanyDay2 = Calendar.getInstance ( ) ;
				enterCompanyDay2.set ( Calendar.YEAR , Integer.parseInt (tempCal.substring(0,4)) ) ;
				enterCompanyDay2.set ( Calendar.MONTH , Integer.parseInt (tempCal.substring(5,7)) ) ;
				enterCompanyDay2.set ( Calendar.DATE , Integer.parseInt (tempCal.substring(8,10)) ) ;
				tempOfficial.setEnterCompanyDay ( enterCompanyDay2 ) ;
				tempOfficial.setHomePhoneNumber ( rslt.getString ( "homePhoneNumber" ) ) ;
				tempOfficial.setFaxNumber ( rslt.getString ( "faxNumber" ) ) ;
				tempOfficial.setOthers ( rslt.getString ( "others" ) ) ;
				allOfficial[index++] = tempOfficial ;				
			}
			allOfficial[index] = new Official ( ) ;
			allOfficial[index].setId ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allOfficial ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			
			Official[] allOfficial = new Official [ 1 ] ;
			Official error = new Official ( ) ;
			error.setId ( "error" ) ;
			error.setPassword ( e.toString ( ) ) ;
			allOfficial[0] = error ;
			
			return allOfficial ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: addOfficial<br>
	 [기능]: 새로운 사원을 등록한다. <br>
	 [파라미터]: Official o<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus addOfficial ( Official o ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			Calendar cal = o.getEnterCompanyDay() ;
			String enterCompanyDay = cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DATE) + "/" + cal.get(Calendar.YEAR) ;

			int sex ;
			if ( o.getSex() ) sex = 1 ;
			else sex = 2 ;
          
          // insert SQL 문장을 만들어서 실행한다.
          String iSQL = "insert into Official values ( \'" + o.getId() + "\',\'" 
						+ o.getPassword() + "\',\'" 
						+ o.getResidentRegistrationNum() + "\',\'" 
						+ o.getFirstName() + "\',\'" 
						+ o.getFamilyName() + "\'," 
						+ sex + "," 
						+ o.getAge() + ",\'" 
						+ o.getAddress() + "\',\'" 
						+ o.getZipCode() + "\',\'" 
						+ o.getPhoneNumber() + "\',\'" 
						+ o.getEmail() + "\',\'" 
						+ o.getPersonalPhone() + "\',\'" 
						+ o.getWeightWork() + "\',\'" 
						+ o.getDepartment() + "\',\'" 
						+ o.getTeam() + "\',\'" 
						+ o.getOrders() + "\',\'" 
						+ enterCompanyDay + "\',\'" 
						+ o.getHomePhoneNumber() + "\',\'" 
						+ o.getFaxNumber() + "\',\'"
						+ o.getOthers() + "\',"
						+ o.getUserKind() + ",\'"          																	 
						+ o.getImagePath() + "\')" ;
			System.out.println ( "만들어진 쿼리는" + iSQL ) ;
			stmt.executeUpdate ( iSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			OrganizationResultStatus ors = new OrganizationResultStatus ( 0 ) ;
			
			con.commit ( ) ;
			
			return ors ;
		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
			ors.setReason ( e.toString ( ) ) ;
			return ors ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: updateOfficial<br>
	 [기능]: 사원의 정보를 업데이트 한다. <br>
	 [파라미터]: Official o<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus updateOfficial ( Official o ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			Calendar cal = o.getEnterCompanyDay() ;
			String enterCompanyDay = cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DATE) + "/" + cal.get(Calendar.YEAR) ;

			int sex ;
			if ( o.getSex() ) sex = 1 ;
			else sex = 2 ;
          
			// update SQL 문장을 만들어서 실행한다.
			String uSQL = "update Official set password=\'" 
						+ o.getPassword() + "\',residentRegistrationNum=\'" 
						+ o.getResidentRegistrationNum() + "\', firstName=\'" 
						+ o.getFirstName() + "\', familyName=\'" 
						+ o.getFamilyName() + "\', sex=" 
						+ sex + ", age=" 
						+ o.getAge() + ", address=\'" 
						+ o.getAddress() + "\', zipCode=\'" 
						+ o.getZipCode() + "\', phoneNumber=\'" 
						+ o.getPhoneNumber() + "\', email=\'" 
						+ o.getEmail() + "\', personalPhone=\'" 
						+ o.getPersonalPhone() + "\', weightWork=\'" 
						+ o.getWeightWork() + "\', department=\'" 
						+ o.getDepartment() + "\', team=\'" 
						+ o.getTeam() + "\', orders=\'" 
						+ o.getOrders() + "\', enterCompanyDay=\'" 
						+ enterCompanyDay + "\', homePhoneNumber=\'" 
						+ o.getHomePhoneNumber() + "\', faxNumber=\'" 
						+ o.getFaxNumber() + "\', userKind=" 
						+ o.getUserKind() + ", imagePath=\'"
						+ o.getImagePath() + "\', others=\'"
	          					+ o.getOthers() + "\'" + "where id=\'" + o.getId() + "\'"  ;
			System.out.println ( "만들어진 쿼리는" + uSQL ) ;
			stmt.executeUpdate ( uSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			OrganizationResultStatus ors = new OrganizationResultStatus ( 0 ) ;
			
			con.commit ( ) ;
			
			return ors ;
		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
			ors.setReason ( e.toString ( ) ) ;
			return ors ;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: deleteOfficial<br>
	 [기능]: 사원을 삭제한다. <br>
	 [파라미터]: Official o<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus deleteOfficial ( Official o ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			// delete SQL 문장을 만들어서 실행한다.
			String dSQL = "delete from Official where id=\'" 
																	+ o.getId() + "\'" ;
			System.out.println ( "만들어진 쿼리는" + dSQL ) ;
			stmt.executeUpdate ( dSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			con.commit ( ) ;
			
			return new OrganizationResultStatus ( ) ;

		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: getAllOfficial<br>
	 [기능]: 팀에 존재하는 모든 사원을 리턴한다. <br>
	 [파라미터]: Team t<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public Official[] getAllOfficial ( Team t ) {

		// 부서의 이름을 알아내자...
		String upDepName = t.getUpDepartment ( ) ;
		// 팀의 이름을 알아내자...
		String team = t.getName ( ) ;

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
          
			// 사원의 명수를 알아낸다.
			ResultSet rslt = stmt.executeQuery( "SELECT COUNT(*) AS OUTPUT FROM Official WHERE department=\'" + upDepName + "\' and team=\'" + team + "\'"  ) ;
			rslt.next ( ) ;
			int officialNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "사원의 숫자를 알아냈습니다." + officialNum + "명 입니다." ) ;
						
			Official[] allOfficial = new Official[officialNum+2] ;
			int index = 0 ;
			
			// 사원을 가져온다.
			rslt = stmt.executeQuery ( "SELECT * FROM Official WHERE department=\'" + upDepName + "\' and team=\'" + team + "\'"  ) ;
						
			while ( rslt.next ( ) ) {
				Official tempOfficial = new Official ( ) ;
				tempOfficial.setId ( rslt.getString ( "id" ) ) ;
				tempOfficial.setPassword ( rslt.getString ( "password" ) ) ;
				tempOfficial.setResidentRegistrationNum ( rslt.getString ( "residentRegistrationNum" ) ) ;
				tempOfficial.setFirstName ( rslt.getString ( "firstName" ) ) ;
				tempOfficial.setFamilyName ( rslt.getString ( "FamilyName" ) ) ;
				if ( rslt.getString ( "sex" ).equals( "1" ) ) {
					tempOfficial.setSex ( true )  ;
				} else {
					tempOfficial.setSex ( false ) ;
				}
				tempOfficial.setAge ( Integer.parseInt( rslt.getString ( "age" ) ) ) ;
				tempOfficial.setAddress ( rslt.getString ( "address" ) ) ;
				tempOfficial.setZipCode ( rslt.getString ( "zipCode" ) ) ;
				tempOfficial.setPhoneNumber ( rslt.getString ( "phoneNumber" ) ) ;
				tempOfficial.setEmail ( rslt.getString ( "email" ) ) ;										
				tempOfficial.setPersonalPhone ( rslt.getString ( "personalPhone" ) ) ;
				tempOfficial.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempOfficial.setDepartment ( rslt.getString ( "department" ) ) ;
				tempOfficial.setTeam ( rslt.getString ( "team" ) ) ;
				tempOfficial.setOrders ( rslt.getString ( "orders" ) ) ;
				String tempCal = rslt.getString ( "enterCompanyDay" ) ;
				Calendar enterCompanyDay = Calendar.getInstance ( ) ;
				enterCompanyDay.set ( Calendar.YEAR , Integer.parseInt (tempCal.substring(0,4)) ) ;
				enterCompanyDay.set ( Calendar.MONTH , Integer.parseInt (tempCal.substring(5,7)) ) ;
				enterCompanyDay.set ( Calendar.DATE , Integer.parseInt (tempCal.substring(8,10)) ) ;
				tempOfficial.setEnterCompanyDay ( enterCompanyDay ) ;
				tempOfficial.setHomePhoneNumber ( rslt.getString ( "homePhoneNumber" ) ) ;
				tempOfficial.setFaxNumber ( rslt.getString ( "faxNumber" ) ) ;
				tempOfficial.setOthers ( rslt.getString ( "others" ) ) ;
				tempOfficial.setUserKind ( Integer.parseInt(rslt.getString ( "userKind" ) ) ) ;
				tempOfficial.setImagePath ( rslt.getString ( "imagePath" ) ) ;
				allOfficial[index++] = tempOfficial ;				
			}
			allOfficial[index] = new Official ( ) ;
			allOfficial[index].setId ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allOfficial ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: getOrganizationTree<br>
	 [기능]: 부서와 팀을 리턴한다. <br>
	 [파라미터]: 없음<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public String[][] getOrganizationTree ( ) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			// 부서의 숫자를 알아낸다.
			ResultSet rslt = stmt.executeQuery( "SELECT COUNT(*) AS OUTPUT FROM Department" ) ;
			rslt.next ( ) ;
			int depNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "부서의 갯수를 알아냈습니다." + depNum + "개 입니다." ) ;
			// 팀의 숫자를 알아낸다.
			rslt = stmt.executeQuery( "SELECT COUNT(*) AS OUTPUT FROM Team" ) ;
			rslt.next ( ) ;
			int teamNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////////////
			System.out.println ( "팀의 갯수를 알아냈습니다." + teamNum + "개 입니다." ) ;
			
			String[][] ot = new String[depNum+2][teamNum+2] ;
			int index = 0 ;
			
			// 부서를 가져온다.
			rslt = stmt.executeQuery ( "SELECT * FROM Department" ) ;
						
			while ( rslt.next ( ) ) {
				ot[index][0] = rslt.getString ( "name" ) ;
				ot[index++][1] = "null" ;
			}
			ot[ index ][0] = "null" ;
			
			// 팀을 가져온다.
			rslt = stmt.executeQuery ( "SELECT * FROM Team" ) ;
			
			while ( rslt.next ( ) ) {
				String upDep = rslt.getString ( "upDepartment" ) ;
				for ( int i = 0 ; i < depNum ; i++ ) {
					if ( ot[i][0].equals(upDep) ) {
						for ( int j = 1 ; j < (teamNum+1) ; j++ ) {
							if ( ot[i][j].equals( "null" ) ) {
								ot[i][j] = rslt.getString ( "name" ) ;
								ot[i][j+1] = "null" ;
								break ;
							}
						}
					}
				}
			}
					
			// Result Set을 닫는다.
			rslt.close ( ) ;
			
			return ot ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
			  	connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: changeDepartment<br>
	 [기능]: 사원의 부서와 팀을 변경한다. ( 부서 발령 )<br>
	 [파라미터]: String id , String department , String team , String orders<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public OrganizationResultStatus changeDepartment ( String id , String department , String team , String orders) {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			con.setAutoCommit ( false ) ;
			
			// update SQL 문장을 만들어서 실행한다.
			String uSQL = "update Official set department=\'" + department 
								+ "\', team=\'" + team 
								+ "\', orders=\'" + orders
								+ "\' where id=\'" + id + "\'" ;
			System.out.println ( "만들어진 쿼리는" + uSQL ) ;
			stmt.executeUpdate ( uSQL ) ;
			System.out.println ( "쿼리가 잘 실행되었습니다" ) ;
			
			con.commit ( ) ;
			
			return new OrganizationResultStatus ( ) ;

		} catch ( Exception e ) {
			try {
				con.rollback ( ) ;
			} catch ( SQLException e2 ) { 
				OrganizationResultStatus ors = new OrganizationResultStatus ( 1 ) ;
				ors.setReason ( e2.toString ( ) ) ;
				return ors ;
			}
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}          
	}
	
	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: getComOfficial<br>
	 [기능]: 부서가 존재하지 않는 사원을 리턴한다.<br>
	 [파라미터]: 없음<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public Official[] getComOfficial () {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			// 사원의 명수를 알아낸다.
			ResultSet rslt = stmt.executeQuery( "SELECT COUNT(*) AS OUTPUT FROM Official WHERE department=\'null\' and team=\'null\'"  ) ;
			rslt.next ( ) ;
			int officialNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "사원의 숫자를 알아냈습니다." + officialNum + "명 입니다." ) ;
						
			Official[] allOfficial = new Official[officialNum+2] ;
			int index = 0 ;
			
			// 사원을 가져온다.
			rslt = stmt.executeQuery ( "SELECT * FROM Official WHERE department=\'null\' and team=\'null\'"  ) ;						
			while ( rslt.next ( ) ) {
				Official tempOfficial = new Official ( ) ;
				tempOfficial.setId ( rslt.getString ( "id" ) ) ;
				tempOfficial.setPassword ( rslt.getString ( "password" ) ) ;
				tempOfficial.setResidentRegistrationNum ( rslt.getString ( "residentRegistrationNum" ) ) ;
				tempOfficial.setFirstName ( rslt.getString ( "firstName" ) ) ;
				tempOfficial.setFamilyName ( rslt.getString ( "FamilyName" ) ) ;
				if ( rslt.getString ( "sex" ).equals( "1" ) ) {
					tempOfficial.setSex ( true )  ;
				} else {
					tempOfficial.setSex ( false ) ;
				}
				tempOfficial.setAge ( Integer.parseInt( rslt.getString ( "age" ) ) ) ;
				tempOfficial.setAddress ( rslt.getString ( "address" ) ) ;
				tempOfficial.setZipCode ( rslt.getString ( "zipCode" ) ) ;
				tempOfficial.setPhoneNumber ( rslt.getString ( "phoneNumber" ) ) ;
				tempOfficial.setEmail ( rslt.getString ( "email" ) ) ;										
				tempOfficial.setPersonalPhone ( rslt.getString ( "personalPhone" ) ) ;
				tempOfficial.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempOfficial.setDepartment ( rslt.getString ( "department" ) ) ;
				tempOfficial.setTeam ( rslt.getString ( "team" ) ) ;
				tempOfficial.setOrders ( rslt.getString ( "orders" ) ) ;
				String tempCal = rslt.getString ( "enterCompanyDay" ) ;
				Calendar enterCompanyDay = Calendar.getInstance ( ) ;
				enterCompanyDay.set ( Calendar.YEAR , Integer.parseInt (tempCal.substring(0,4)) ) ;
				enterCompanyDay.set ( Calendar.MONTH , Integer.parseInt (tempCal.substring(5,7)) ) ;
				enterCompanyDay.set ( Calendar.DATE , Integer.parseInt (tempCal.substring(8,10)) ) ;
				tempOfficial.setEnterCompanyDay ( enterCompanyDay ) ;
				tempOfficial.setHomePhoneNumber ( rslt.getString ( "homePhoneNumber" ) ) ;
				tempOfficial.setFaxNumber ( rslt.getString ( "faxNumber" ) ) ;
				tempOfficial.setOthers ( rslt.getString ( "others" ) ) ;
				allOfficial[index++] = tempOfficial ;				
			}
			allOfficial[index] = new Official ( ) ;
			allOfficial[index].setId ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allOfficial ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}

	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: getDepOfficial<br>
	 [기능]: 부서는 존재하지만 팀이 존재하지 않는 사원을 리턴한다.<br>
	 [파라미터]: 없음<br>
	 [호출자] : OrganizationManagementController<br>
	 */
	/*--------------------------------------------------------------- */
	public Official[] getDepOfficial () {

		Connection con = null ;
		Statement stmt = null ;
		
		try {
			con = connectionManager.getConnection("access");
			//////////////////////////
			System.out.println ( "커넥션 풀 객체로부터 커넥션을 얻어냈습니다." ) ;
			
			stmt = con.createStatement ();   
			//////////////////////////
			System.out.println ( "커넥션으로부터 스테이트먼트를 얻어냈습니다." ) ;
			
			// 사원의 명수를 알아낸다.
			ResultSet rslt = stmt.executeQuery( "SELECT COUNT(*) AS OUTPUT FROM Official WHERE department!=\'null\' and team=\'null\'"  ) ;
			rslt.next ( ) ;
			int officialNum = rslt.getInt( "OUTPUT" ) ; 
			////////////////////////////
			System.out.println ( "사원의 숫자를 알아냈습니다." + officialNum + "명 입니다." ) ;
						
			Official[] allOfficial = new Official[officialNum+2] ;
			int index = 0 ;
			
			// 사원을 가져온다.
			rslt = stmt.executeQuery ( "SELECT * FROM Official WHERE department!=\'null\' and team=\'null\'"  ) ;						
			while ( rslt.next ( ) ) {
				Official tempOfficial = new Official ( ) ;
				tempOfficial.setId ( rslt.getString ( "id" ) ) ;
				tempOfficial.setPassword ( rslt.getString ( "password" ) ) ;
				tempOfficial.setResidentRegistrationNum ( rslt.getString ( "residentRegistrationNum" ) ) ;
				tempOfficial.setFirstName ( rslt.getString ( "firstName" ) ) ;
				tempOfficial.setFamilyName ( rslt.getString ( "FamilyName" ) ) ;
				if ( rslt.getString ( "sex" ).equals( "1" ) ) {
					tempOfficial.setSex ( true )  ;
				} else {
					tempOfficial.setSex ( false ) ;
				}
				tempOfficial.setAge ( Integer.parseInt( rslt.getString ( "age" ) ) ) ;
				tempOfficial.setAddress ( rslt.getString ( "address" ) ) ;
				tempOfficial.setZipCode ( rslt.getString ( "zipCode" ) ) ;
				tempOfficial.setPhoneNumber ( rslt.getString ( "phoneNumber" ) ) ;
				tempOfficial.setEmail ( rslt.getString ( "email" ) ) ;										
				tempOfficial.setPersonalPhone ( rslt.getString ( "personalPhone" ) ) ;
				tempOfficial.setWeightWork ( rslt.getString ( "weightWork" ) ) ;
				tempOfficial.setDepartment ( rslt.getString ( "department" ) ) ;
				tempOfficial.setTeam ( rslt.getString ( "team" ) ) ;
				tempOfficial.setOrders ( rslt.getString ( "orders" ) ) ;
				String tempCal = rslt.getString ( "enterCompanyDay" ) ;
				Calendar enterCompanyDay = Calendar.getInstance ( ) ;
				enterCompanyDay.set ( Calendar.YEAR , Integer.parseInt (tempCal.substring(0,4)) ) ;
				enterCompanyDay.set ( Calendar.MONTH , Integer.parseInt (tempCal.substring(5,7)) ) ;
				enterCompanyDay.set ( Calendar.DATE , Integer.parseInt (tempCal.substring(8,10)) ) ;
				tempOfficial.setEnterCompanyDay ( enterCompanyDay ) ;
				tempOfficial.setHomePhoneNumber ( rslt.getString ( "homePhoneNumber" ) ) ;
				tempOfficial.setFaxNumber ( rslt.getString ( "faxNumber" ) ) ;
				tempOfficial.setOthers ( rslt.getString ( "others" ) ) ;
				allOfficial[index++] = tempOfficial ;				
			}
			allOfficial[index] = new Official ( ) ;
			allOfficial[index].setId ( "null" ) ;
										
			// Result Set을 닫는다.
			rslt.close ( ) ;
						
			return allOfficial ;
		} catch ( Exception e ) {
			System.out.println ( e.toString ( ) ) ;
			return null;
		} finally {
			try { 
				if ( stmt != null ) { stmt.close ( ) ; } 
			} catch ( SQLException sqle ) {
				while ( sqle != null ) {
					System.out.println ( "SQLState : " + sqle.getSQLState ( ) ) ;
					System.out.println ( "Message : " + sqle.getMessage ( ) ) ; 
					System.out.println ( "Error Code : " + sqle.getErrorCode ( ) ) ;
					sqle = sqle.getNextException ( ) ;
					System.out.println ( " " ) ;
				} ;
				connectionManager.freeConnection ("access", con ) ;  
			}
			connectionManager.freeConnection ("access", con ) ;  
		}
	}


	
}

      