import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class ScheduleFlight extends HttpServlet {


    private boolean isIncoming(String flightnum) {
        boolean toReturn = false;
        Connection conn = ConnectionManager.getInstance().getConnection();

        String sql = "SELECT * FROM IncomingFlight WHERE num=" + flightnum;

        try {
            Statement st = conn.createStatement();
            ResultSet res = st.executeQuery(sql);
            while (res.next()) {
                toReturn = true;
            }

            st.close();


        } catch (SQLException e) {
            return false;
        }

        return toReturn;
    }

    private String formatDate(String date) {
        return "TO_DATE('" + date.trim() + "'" +
        ", 'dd/mm/yyyy')";
    }

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {


    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    String flightnum = request.getParameter("flight");
    String id = request.getParameter("id");
    String gate = request.getParameter("gate");
    String date = request.getParameter("date");
    
    String association = "";
    String info = "";
    if (isIncoming(flightnum)) {
        association = "INSERT INTO Incoming (flightnumber, arrivalid) " +
                      "VALUES ('" + flightnum + "'," +
                      "'" + id + "')";
        info = "INSERT INTO Arrivals (gate, arrivedate, arriveid) " +
               "VALUES ('" + gate + "'," +
               "" + formatDate(date) + "," +
               "" + id + ")";
    } else {
        association = "INSERT INTO Outgoing (flightnumber, departid) " +
                      "VALUES ('" + flightnum + "'," +
                      "'" + id + "')";
        info = "INSERT INTO Departures (gate, arrivedate, departid) " +
               "VALUES ('" + gate + "'," +
               "" + formatDate(date) + "," +
               "" + id + ")";
    }
 
    Connection conn = ConnectionManager.getInstance().getConnection();

    String resp = "";
    try {
        Statement st = conn.createStatement();
        st.executeUpdate(info);
        st.executeUpdate(association);

        st.close();


    } catch (SQLException e) {
         resp = "Encountered error: " + e; 
    }

    resp += "<html><head><title>Successfully inserted</title></head>" +
            "<body><p>Successfully scheduled new flight on <b>" + date +
            "</b>. <a href='/servlet/ScheduleFlightForm'>Go Back</a>.</p></body></html>";

    String docType =
      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
      "Transitional//EN\">\n";
    out.println(docType + resp);

  }
}

@@ -715,24 +715,879 @@
 urn;%0A    %7D%0A%0A
+%0A    private String getTime(String flight) %7B%0A        String sql = %22%22;%0A        boolean incoming = false;%0A        if (isIncoming(flight)) %7B%0A            incoming = true;%0A            sql = %22SELECT plannedArrival FROM IncomingFlight WHERE num='%22 + flight + %22'%22;  %0A        %7D else %7B%0A            sql = %22SELECT plannedDeparture FROM OutgoingFlight num='%22 + flight + %22'%22;%0A        %7D%0A    %0A        Connection conn = ConnectionManager.getInstance().getConnection();%0A%0A        try %7B%0A            Statement st = conn.createStatement();%0A            ResultSet res = st.executeQuery(sql);%0A            while (res.next()) %7B%0A                if (incoming) return res.getString(%22plannedArrival%22);%0A                else return res.getString(%22plannedDeparture%22);%0A            %7D%0A%0A            st.close();%0A%0A%0A        %7D catch (SQLException e) %7B%0A            return false;%0A        %7D%0A%0A%0A    %7D%0A%0A
     private 
@@ -1690,16 +1690,27 @@
 /mm/yyyy
+ hh24:mi:ss
 ')%22;%0A   
@@ -2139,26 +2139,25 @@
 %22date%22);%0A   
- 
 %0A
+
     String a
@@ -2169,24 +2169,24 @@
 ation = %22%22;%0A
-
     String i
@@ -2190,24 +2190,107 @@
 g info = %22%22;
+i%0A%0A    String time = getTime(flightnum);%0A    %0A    date = date + time.split(%22 %22)%5B1%5D;
 %0A    if (isI

Fix datetime issue