package ibase.webitm.ejb.mfg;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
//import ibase.utility.GenericUtility;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction;
import org.w3c.dom.*;
import javax.ejb.EJBException;


/**
 *
 * @author cpandey
 */
@Stateless
public class WIPScanPvSolar extends ValidatorEJB implements WIPScanPvSolarRemote,WIPScanPvSolarLocal
{
	GenericUtility genericUtility=GenericUtility.getInstance();


	public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws ITMException
	{
		String errString="";
		Document dom=null;
		Document dom1=null;

		try {
			System.out.println("xmlString---------"+xmlString);
			System.out.println("xmlString1---------"+xmlString1);
			dom = parseString(xmlString);
			dom1=parseString(xmlString1);
			errString=wfValData(dom, dom1, objContext, editFlag, xtraParams);

		} catch (RemoteException ex)
		{
			throw new ITMException(ex);
		}
		return errString;
	}
	public String wfValData(Document dom,Document dom1,String objContext,String editFlag,String xtraParams) throws RemoteException,ITMException
	{

		NodeList parentNodeList=null;
		NodeList childNodeList=null;
		Node parentNode=null;
		Node childNode=null;
		String childNodeName=null;
		int childNodeListLength=0;
		String errString="";
		String errCode="";
		String errFieldName="";
		String errorType="";
		String userId="";
		Connection conn=null;
		GenericUtility genutility=null;
		String lotNo= "";     //LOT NO FOR BAR CODE READING FIELD  FROM WORKORDER TABLE 
		String lotSl= ""; 
		String siteCode = "";//LOT SL FOR BAR CODE READING FIELD FROM WORKORDER TABLE
		String workOrd = "";   //WORK_ORDER FROM WORKORDER TABLE
		String itemCode = "";   //ITEM CODE FROM WORKORDER TABLE 
		String conf = "";       //CONFIRMED FOR WIP_SCANNING_HDR TABLE   
		ResultSet rs=null;
		int cont = 0;
		int currentFormNo=0;
		PreparedStatement pstmt = null;
		ArrayList <String> errList=new ArrayList<String>();
		ArrayList<String> errFields = new ArrayList<String>();
		ConnDriver connDriver=new ConnDriver();
		StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");

		try
		{
			genutility=GenericUtility.getInstance();
			conn=connDriver.getConnectDB("DriverITM");
			connDriver=null;
			userId=getValueFromXTRA_PARAMS(xtraParams,"loginCode");
			System.out.println("1---currentFormNo-------"+currentFormNo);
			if(objContext!=null && objContext.trim().length()>0)
			{
				currentFormNo=Integer.parseInt(objContext);
			}
			System.out.println("2----currentFormNo-------"+currentFormNo);
			switch(currentFormNo)
			{
			case 1:
				parentNodeList=dom.getElementsByTagName("Detail1");
				parentNode=parentNodeList.item(0);
				childNodeList=parentNode.getChildNodes();
				childNodeListLength=childNodeList.getLength();

				for(int ctr=0;ctr<childNodeListLength;ctr++)
				{
					childNode=childNodeList.item(ctr);
					childNodeName=childNode.getNodeName();
					if (childNodeName.equalsIgnoreCase("lot_no"))
					{
						lotNo = getColumnValue("lot_no", dom);
						System.out.println("This is in wfValdata Case1 & Emp_id is \t"+lotNo);
						if ( lotNo != null || lotNo.trim().length() == 0 )
						{
							errList.add("WIPB1"); 
							errFields.add("lotNo");
							System.out.println("Bar code Comming null in wfvaldata & bar_code is : \t"+lotNo);
						}	
					}
					else if (childNodeName.equalsIgnoreCase("lot_sl"))
						{
						lotNo = getColumnValue("lot_no", dom);	
						lotSl = getColumnValue("lot_sl", dom);
						
													
							String sql = "SELECT W1.WORK_ORDER,W1.ITEM_CODE FROM WORKORDER W1 WHERE W1.LOT_NO = ? AND W1.LOT_SL = ? ";
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1,lotNo);
							pstmt.setString(2,lotSl);
							rs = pstmt.executeQuery();
							while(rs.next())
							{
									System.out.println("All column value ");
									workOrd=rs.getString("WORK_ORDER");
									System.out.println("WORK_ORDER"+workOrd);
									itemCode=rs.getString("ITEM_CODE");
									System.out.println("item code"+itemCode);
									
								}
							pstmt.close();
							rs.close();
							pstmt = null;
							rs = null;
							//SELECTING CONFIRMED COLUMN FOR SCANNING FROM WORKORDER ISS
							pstmt = conn.prepareStatement("SELECT CONFIRMED FROM WORKORDER_ISS WHERE WORK_ORDER = ?");
							pstmt.setString(1,workOrd);
							rs = pstmt.executeQuery();
							while(rs.next())
							{
								conf=rs.getString("confirmed");
							}
							pstmt.close();
							rs.close();
							pstmt = null;
							rs = null;
							if(conf =="N")
							{
								errList.add("WIPINVBC");
								errFields.add("conf");
								System.out.println("confirmed field ");
							}
							//VALIDATION FOR LOT SL
							System.out.println("This is in wfValdata Case1 & Emp_id is \t"+lotSl);
							if ( lotSl != null || lotSl.trim().length() == 0 )
							{
								String sql1 = " SELECT COUNT(*) FROM WORKORDER WHERE LOT_SL = ? ";
								pstmt =  conn.prepareStatement(sql1);
								pstmt.setString(1,workOrd);
								rs = pstmt.executeQuery();
								if(rs.next())
								{
									cont =  rs.getInt(1);
									if(cont == 0) 
									{
										errList.add("WIPB1"); 
										errFields.add("lotSl");
										System.out.println("Lot_sl Comming null in wfvaldata & bar_code is : \t"+lotSl);
										break ;
									}									
								}
								rs.close();
								rs = null;
								pstmt.close();
								pstmt = null;
								
							}							
					}
						
					//VALIDATION FOR QC APPROVAL REJECT
						if (childNodeName.equalsIgnoreCase("qc_approval_reject"))
						{
							String qc_approval_reject = getColumnValue("qc_approval_reject", dom);
							System.out.println("This is in wfValdata Case1 & Emp_id is \t"+qc_approval_reject);
							if ( qc_approval_reject == null || qc_approval_reject.trim().length() == 0 )
							{
								errList.add("WIPQCAR1"); 
								errFields.add("qc_approval_reject");
								System.out.println("Bar code Comming null in wfvaldata & bar_code is : \t"+qc_approval_reject);
							}							
						}
						//VALIDATION FOR REASON CODE
						if (childNodeName.equalsIgnoreCase("reason_code"))
						{
							String reason_code = getColumnValue("reason_code", dom);
							System.out.println("This is in wfValdata Case1 & Emp_id is \t"+reason_code);
							if ( reason_code == null || reason_code.trim().length() == 0 )
							{
								errList.add("WIPRC1"); 
								errFields.add("reason_code");
								System.out.println("Bar code Comming null in wfvaldata & bar_code is : \t"+reason_code);
							}							
						}
						if (childNodeName.equalsIgnoreCase("remarks"))
						{
							String remarks = getColumnValue("remarks", dom);
							System.out.println("This is in wfValdata Case1 & Emp_id is \t"+remarks);
							if ( remarks == null || remarks.trim().length() == 0 )
							{
								errList.add("WIPQCAR1"); 
								errFields.add("remarks");
								System.out.println("Bar code Comming null in wfvaldata & bar_code is : \t"+remarks);
							}							
						}			

				break;

			}
			int errListSize=errList.size();
			if(errListSize>0)
			{
				for(int cnt=0;cnt<errListSize;cnt++)
				{
					errCode=errList.get(cnt);
					errFieldName=errFields.get(cnt);
					errString=getErrorString(errFieldName, errCode, userId);
					errorType =  errorType( conn , errCode );

					if ( errString.length() > 0)
					{
						String bifurErrString = errString.substring( errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
						bifurErrString = bifurErrString;
						bifurErrString = bifurErrString+errString.substring( errString.indexOf("</trace>") + 8,errString.indexOf("</Errors>"));
						errStringXml.append(bifurErrString);
						errString = "";
					}

					if ( errorType.equalsIgnoreCase("E"))
					{
						break;
					}
				}
				errList.clear();
				errList = null;
				errFields.clear();
				errFields = null;
				errStringXml.append("</Errors></Root>\r\n");
			}else
			{
				errStringXml = new StringBuffer( "" );
			}
			}
		}
			catch(Exception e)
		{
			System.out.println(e);
			e.printStackTrace();
		}
		finally
		{

			try
			{
				if(conn!=null)
				{
					conn.close();
				}
				conn=null;
			} catch (Exception ex) {
				Logger.getLogger(WIPScanPvSolar.class.getName()).log(Level.SEVERE, null, ex);
			}
		}
		errString = errStringXml.toString();
		return errString;
	}

	public String itemChanged(String xmlString, String xmlString1,String objContext,String currentColumn,String editFlag,String xtraParams)
	{
		System.out.println(" $$ xmlString ::"+xmlString);
		System.out.println(" $$ xmlString2 ::"+xmlString1);
		
		Document dom=null;
		Document dom1=null;
		String valueXmlString="";
		try
		{
			dom = parseString(xmlString);
			dom1 = parseString(xmlString1);
			valueXmlString=itemChanged(dom, dom1, objContext, currentColumn, editFlag, xtraParams);
		}catch(Exception e)
		{
			System.out.println(e);
		}
		return valueXmlString;
	}

	public String itemChanged(Document dom,Document dom1,String objContext,String currentColumn,String editFlag,String xtraParams)
	{
		NodeList parentNodeList=null;
		NodeList childNodeList=null;
		Node parentNode=null;
		Node childNode=null;
		String childNodeName=null;
		int childNodeListLength=0;
		ConnDriver connDriver=new ConnDriver();
		Connection conn=null;
		StringBuffer valueXmlString=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		int currentFormNo=0;
		String lotNo= "";                //LOT NO FOR SCANING BAR CODE
		String lotSl= "";                //LOT SL FOR SCANING BAR CODE
		int ctr;
		String columnValue = "";
		String opreration = "";        //OPERATION FROM WORKORDER_FEEDBACK
		String procCode = "";          //PROCESS CODE FOR WIP_SCANNING_HDR FROM WORKORDER 
		String procDescr = "";          //PROCESS DESCR FOR WIP_SCANNING_HDR FROM WORKORDER_ROUTE
		String workOrd = "";            //WORKORDER FROM WORKORDER TABLE
		String itemCode = "";
		GenericUtility genutility=null;
		String mcCode= "";   
		String siteCode = "";
		String runStartTime = "" ;       //SCANNING TIME
		Date runEndTime  = null;         //RUN END TIME FROM WORKORDER_FEEDBACK TABLE  
		Double waitTime = 0.0;           //FROM WORKORDER_FEEDBACK TABLE
		double totalRunTime = 0.0 ;        //DEFRENCE BETWEEN START TIME AND END TIME
		Double cummulRunTime  = 0.0;        //TOTAL RUN TIME
		String prodDescr = "";              //ITEM DESCR FROM ITEM TABLE 
		String reasonCode = "";  
		String sql = "";//FLD VALUE FROM REASON CODE
		String reasonDescr = "";              //DESCR FROM REASON CODE
		String qcApprovalReject = "";         //FROM WIP_SCANNING_HDR    

		try
		{
			genutility=GenericUtility.getInstance();
			conn = connDriver.getConnectDB("DriverITM");
			conn.setAutoCommit(false);
			connDriver=null;
			siteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");			
			System.out.println("^^^^^^^^^SITE CODE^^^^^^^^^^^^^"+siteCode);
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat(genericUtility.getApplDateFormat());
			SimpleDateFormat simpleDateTimeFormat = new SimpleDateFormat(genericUtility.getApplDateTimeFormat());
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
			valueXmlString.append(editFlag).append("</editFlag></header>");
			switch(currentFormNo)
			{
			case 1 :
				parentNodeList = dom.getElementsByTagName("Detail1");
				parentNode = parentNodeList.item(0);
				childNodeList = parentNode.getChildNodes();
				ctr = 0;
				valueXmlString.append("<Detail>");
				System.out.println("+++++++++++++current form no++++++++++"+currentFormNo);
				childNodeListLength = childNodeList.getLength();
				do
				{
					childNode = childNodeList.item(ctr);
					childNodeName = childNode.getNodeName();
					if(childNodeName.equals(currentColumn))
					{
						if (childNode.getFirstChild() != null)
						{
							columnValue = childNode.getFirstChild().getNodeValue().trim();
						}
						System.out.println("in do while loop "+columnValue);
					}
					ctr++;
				}while(ctr < childNodeListLength  && !childNodeName.equals(currentColumn));
				System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
				if(currentColumn.trim().equalsIgnoreCase("itm_default"))	
				{
					qcApprovalReject = genericUtility.getColumnValue("qc_approval_reject",dom);
					valueXmlString.append("<tran_date>").append("<![CDATA["+simpleDateFormat.format(new Date())+"]]>").append("</tran_date>");
					valueXmlString.append("<confirmed><![CDATA[").append("N").append("]]></confirmed >");
							valueXmlString.append("<reason_code protect=\"1\">").append("").append("</reason_code>");
				}
				
				if(currentColumn.trim().equalsIgnoreCase("lot_no"))
				{
					System.out.println("Current column["+currentColumn+"]");
					lotNo = genericUtility.getColumnValue("lot_no",dom);
				    if(lotNo !=null && lotNo.trim().length() >0 )
					{
						lotNo = lotNo.toUpperCase();
						System.out.println("lot no  "+lotNo);
					}
					System.out.println("lot no  "+lotNo);
					valueXmlString.append("<lot_no>").append("<![CDATA["+lotNo+"]]>").append("</lot_no>");
					valueXmlString.append("<tran_date>").append("<![CDATA["+simpleDateFormat.format(new Date())+"]]>").append("</tran_date>");
				}
				else if(currentColumn.trim().equalsIgnoreCase("lot_sl"))
				{
					 System.out.println("Current column["+currentColumn+"]");
					lotSl = genericUtility.getColumnValue("lot_sl",dom) ;
					lotNo = genericUtility.getColumnValue("lot_no",dom) ;
					runStartTime = genericUtility.getColumnValue("run_time_start",dom) ;
					 sql = "SELECT W1.WORK_ORDER,W1.ITEM_CODE FROM WORKORDER W1 WHERE W1.LOT_NO = ? AND W1.LOT_SL = ? ";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1,lotNo);
					pstmt.setString(2,lotSl);
					rs = pstmt.executeQuery();
					while(rs.next())
					{
							workOrd=rs.getString("WORK_ORDER");
							itemCode=rs.getString("ITEM_CODE");
							
						}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
				 sql = 	" SELECT OPERATION,WAIT_TIME,PROC_CODE,DESCR FROM WORDER_ROUTE WR ,WORKORDER W1 WHERE WR.WORK_ORDER= W1.WORK_ORDER AND W1.WORK_ORDER = ?" ;
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,workOrd);
				rs = pstmt.executeQuery();
				if(rs.next()) 
				{
					int operation1 = 0;
					opreration =  rs.getString("operation");
					operation1 = operation1+1; 
					operation1 = operation1+1;
					waitTime=rs.getDouble("wait_time");
					procCode=rs.getString("proc_code");
					procDescr=rs.getString("descr");
					
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;

				 sql = 	" SELECT DESCR FROM PROCESS WHERE PROC_CODE = ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1,procCode);
					rs = pstmt.executeQuery();
					if(rs.next()) 
					{						
						procDescr=rs.getString("descr");						
					}
					rs.close();
					rs = null;
					pstmt.close();
					pstmt = null;
					
				
				
				 sql = "SELECT DESCR FROM ITEM WHERE ITEM_CODE = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,itemCode);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					prodDescr=rs.getString("DESCR");
				}
				rs.close();
				rs = null; 
				pstmt.close();
				pstmt = null;
				
				sql ="SELECT RUN_TIME_START,RUN_TIME_END FROM WORKORDER_FEEDBACK WF,WORKORDER W1 WHERE WF.WORK_ORDER = W1.WORK_ORDER AND W1.WORK_ORDER = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,workOrd);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					runEndTime=rs.getTimestamp("RUN_TIME_END");
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				 
				sql = "SELECT RUN_TIME_START-RUN_TIME_END AS TOTAL_RUN_TIME FROM  WORKORDER_FEEDBACK WF,WORKORDER W1 WHERE W1.WORK_ORDER = WF.WORK_ORDER AND W1.WORK_ORDER = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,workOrd);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					//totalRunTime=rs.getString("TOTAL_RUN_TIME");
					System.out.println("TOTAL RUN TIME"+totalRunTime);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				
				sql = "SELECT MC_CODE FROM WORDER_ROUTE WHERE OPERATION = ? AND WORK_ORDER = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,opreration);
				pstmt.setString(2,workOrd);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					mcCode=rs.getString("mc_code");
					System.out.println("TOTAL RUN TIME"+cummulRunTime);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				
				sql = "SELECT SUM(RUN_TIME) AS CUMULATIVE_TIME FROM WORDER_ROUTE WR,WORKORDER W1 WHERE WR.WORK_ORDER = W1.WORK_ORDER AND W1.WORK_ORDER = ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1,workOrd);
				rs = pstmt.executeQuery();
				if(rs.next())
				{
					cummulRunTime=rs.getDouble("cumulative_time");
					System.out.println("TOTAL RUN TIME"+cummulRunTime);
				}
				rs.close();
				rs = null;
				pstmt.close();
				pstmt = null;
				 
					valueXmlString.append("<work_order>").append("<![CDATA[" +workOrd+ "]]>").append("</work_order>");
					valueXmlString.append("<lot_no>").append("<![CDATA[" + lotNo + "]]>").append("</lot_no>");
					valueXmlString.append("<lot_sl>").append("<![CDATA[" + lotSl + "]]>").append("</lot_sl>");
					valueXmlString.append("<product_code>").append("<![CDATA[" + itemCode + "]]>").append("</product_code>");
					valueXmlString.append("<descr>").append("<![CDATA[" + prodDescr + "]]>").append("</descr>");
					valueXmlString.append("<operation>").append("<![CDATA[" + opreration + "]]>").append("</operation>");
					valueXmlString.append("<proc_code>").append("<![CDATA[" +procCode+ "]]>").append("</proc_code>");
					valueXmlString.append("<site_code>").append("<![CDATA[" + siteCode+ "]]>").append("</site_code>");
					valueXmlString.append("<process_descr>").append("<![CDATA[" + procDescr + "]]>").append("</process_descr>");
					valueXmlString.append("<wait_time>").append("<![CDATA[" + waitTime + "]]>").append("</wait_time>");
					valueXmlString.append("<mc_code>").append("<![CDATA[" + mcCode + "]]>").append("</mc_code>");
					valueXmlString.append("<run_start_time>").append("<![CDATA["+simpleDateTimeFormat.format(new Timestamp(System.currentTimeMillis()))+"]]>").append("</run_start_time>");
					valueXmlString.append("<run_end_time>").append("<![CDATA["+ simpleDateTimeFormat.format(runEndTime) + "]]>").append("</run_end_time>");
					System.out.println("END TIME"+runEndTime);
					try{
						if(runEndTime != null )
						{
							double runTime = ((System.currentTimeMillis())-(runEndTime.getTime()))/3600000 ;
							totalRunTime = runTime ;
							valueXmlString.append("<total_run_time>").append("<![CDATA[" + totalRunTime+ "]]>").append("</total_run_time>");
						}
					}
					catch(NullPointerException nop)
					{
						nop.printStackTrace();
					}
					valueXmlString.append("<cumulativ_run_time>").append("<![CDATA[" + cummulRunTime + "]]>").append("</cumulativ_run_time>");
					valueXmlString.append("<gencodes_descr>").append("<![CDATA["+reasonDescr+"]]>").append("</gencodes_descr>");
				}
				
				if(currentColumn.trim().equalsIgnoreCase("qc_approval_reject"))
				{
					qcApprovalReject = genericUtility.getColumnValue("qc_approval_reject",dom);
					if("A".equals(qcApprovalReject) )
					{
						valueXmlString.append("<reason_code protect=\"1\">").append("").append("</reason_code>");
					}
					else
					{
						valueXmlString.append("<reason_code protect=\"0\">").append("").append("</reason_code>");
					}
				}
				
				 if(currentColumn.trim().equalsIgnoreCase("reason_code"))
				{
					reasonCode = genericUtility.getColumnValue("reason_code",dom);
					if(reasonCode != null && reasonCode.length()== 0)
					{
						System.out.println("reason_code comming null in itemChanged event of case 1");
					}
					pstmt= conn.prepareStatement("SELECT DESCR FROM GENCODES WHERE fld_value = ? ");
					pstmt.setString(1,reasonCode);
					rs = pstmt.executeQuery();
					if(rs.next())
					{
						reasonDescr = rs.getString(1);
					}
					pstmt.close();
					rs.close();
					pstmt = null;
					rs = null;
					valueXmlString.append("<gencodes_descr>").append("<![CDATA["+reasonDescr+"]]>").append("</gencodes_descr>");					
				}
				
				valueXmlString.append("</Detail>");
				break ;
			}//switch case end
			valueXmlString.append("</Root>");
		}//try end
		catch(Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if(conn!=null)
				{
					if(pstmt != null)
						pstmt.close();
					if(rs != null)
						rs.close();
					rs = null;
					pstmt = null;
					conn.close();
					conn = null;
				}

			}catch(Exception d)
			{
				d.printStackTrace();
			}
		}
		System.out.println("VALUE STRING"+valueXmlString.toString());
		return valueXmlString.toString();
	}
	private String errorType( Connection conn , String errorCode )
	{
		String msgType = "";
		System.out.println("IN ERROR METHOD");
		PreparedStatement pstmt = null ;
		ResultSet rs = null;
		try
		{
			String  sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO =   ? ";
			System.out.println("SQL IS EXECUTING");
			pstmt = conn.prepareStatement( sql );
			pstmt.setString( 1, errorCode );
			rs = pstmt.executeQuery();
			while( rs.next() )
			{
				msgType = rs.getString("MSG_TYPE");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			try
			{
				if ( rs != null )
				{
					rs.close();
					rs = null;
				}
				if ( pstmt != null )
				{
					pstmt.close();
					pstmt = null;
				}
			}
			catch ( Exception e )
			{
				e.printStackTrace();
			}
		}
		return msgType;
	}

}

