<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link href="css/sty.css" rel="stylesheet" type="text/css"></link>        
</head>
<body>
<%@page language="java" import="java.text.*,java.util.*,java.sql.*" contentType="text/html"%>

<%
		 Number serial=Integer.parseInt(request.getParameter("serial"));
          String lettertype="";
	
			 try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:letter");
            PreparedStatement pstmt = con.prepareStatement("select lettertype  from tappal_number where sno="+serial+"");
                      
              ResultSet rs= pstmt.executeQuery();

		   while(rs.next())
            {
                lettertype=rs.getString(1);
			}
           
			 
			 
			 if(lettertype.equals("incoming"))
			   { 
				 
			
 PreparedStatement pstmt1 = con.prepareStatement("delete from  i_tappals where serial="+serial+"");
 int  j= pstmt1.executeUpdate();
 
}

 		  if(lettertype.equals("outgoing"))
			   {
				             PreparedStatement pstmt2= con.prepareStatement("delete  from o_tappals where serial="+serial+"");
                    int  i= pstmt2.executeUpdate();
 	
  
			   }	   
		   
		   
		   
		   

        PreparedStatement pstmt3= con.prepareStatement("delete  from tappal_number where sno="+serial+"");
           int  k= pstmt3.executeUpdate();
	if(k>0)
		{
              request.setAttribute("insert","DeletedSuccessfully");
               RequestDispatcher rd = request.getRequestDispatcher("delete.jsp");
               rd.forward(request, response);
		}
else
		{
				    request.setAttribute("error","Not  Found ");
                   RequestDispatcher rd=request.getRequestDispatcher("delete.jsp");
                rd.forward(request, response);
		}
   	 
	
		   con.close();
		   
	   }

catch(Exception s)
        { 
	out.println(s);
   	  
	}
	
	
	%>
</body>
</html>