import java.io.IOException;
import java.io.PrintStream;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.*;

public class ContractStatus extends HttpServlet
{

    public ContractStatus()
    {
    }

    public void service(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
    {
        ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection connection = DriverManager.getConnection("Jdbc:Odbc:JDSN", "scott", "tiger");
            String s = httpservletrequest.getParameter("TYPE");
            if(s.equalsIgnoreCase("INSERT"))
            {
                PreparedStatement preparedstatement = connection.prepareStatement("INSERT INTO Con_Status values(?,?,?)");
                preparedstatement.setInt(1, Integer.parseInt(httpservletrequest.getParameter("TContractId")));
                preparedstatement.setInt(2, Integer.parseInt(httpservletrequest.getParameter("TExecId")));
                preparedstatement.setString(3, httpservletrequest.getParameter("TStatus"));
                preparedstatement.execute();
                connection.commit();
                servletoutputstream.println("Record Inserted");
                System.out.println("Record Inserted");
            } else
            if(s.equalsIgnoreCase("DELETE"))
            {
                PreparedStatement preparedstatement1 = connection.prepareStatement("DELETE From Con_Status where ContId=?");
                preparedstatement1.setInt(1, Integer.parseInt(httpservletrequest.getParameter("TContractId")));
                preparedstatement1.execute();
                connection.commit();
                servletoutputstream.println("Record Deleted");
                System.out.println("Record Deleted");
            } else
            if(s.equalsIgnoreCase("MODIFY"))
            {
                PreparedStatement preparedstatement2 = connection.prepareStatement("Update Con_Status set Exec_Id=?,status=? where ContId=?");
                preparedstatement2.setInt(1, Integer.parseInt(httpservletrequest.getParameter("TExecId")));
                preparedstatement2.setString(2, httpservletrequest.getParameter("TStatus"));
                preparedstatement2.setInt(3, Integer.parseInt(httpservletrequest.getParameter("TContractId")));
                preparedstatement2.execute();
                connection.commit();
                servletoutputstream.println("Record Updated");
                System.out.println("Record Updated");
            }
        }
        catch(Exception exception)
        {
            servletoutputstream.println(exception.toString());
            System.out.println(exception.toString());
        }
    }
}