private void CheckButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CheckButtonActionPerformed

        String flightno = FlightNoTextField.getText();
        if (flightno.equals("")) {
            return;
        }
        StatusPanel.setVisible(true);
        try {
            Connection con;
            con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "oracle");
            Statement st1 = con.createStatement();
            Statement st2 = con.createStatement();

            String from = "", to = "", via = "", status = "";

            ResultSet rs1 = st1.executeQuery("select a.aid, a.city "
                    + "from flight, airport a "
                    + "where flightno='" + flightno + "'"
                    + "  and a.aid in (depID,arrID) "
                    + "group by a.aid,a.city  "
                    + "having count(aid)=1");

            ResultSet rs3 = st2.executeQuery("select status from flight where flightno='" + flightno + "'");
            if (rs3.next()) {
                status = rs3.getString(1);
            } else {
                StatusTextArea.setText("No such flight exists!");
                con.close();
                return;
            }

            while (rs1.next()) {

                ResultSet rs2 = st2.executeQuery("Select a.aid,a.apname,a.iatacode,a.city from airport a, flight f"
                        + " where flightno='" + flightno + "'"
                        + "  and a.aid=depID "
                        + "  and a.aid=" + rs1.getInt(1));

                if (rs2.next()) {
                    from = rs2.getString(2) + " Airport (" + rs2.getString(3) + "), " + rs2.getString(4);
                }

                rs2 = st2.executeQuery("select a.aid,a.apname,a.iatacode,a.city from airport a, flight f"
                        + " where flightno='" + flightno + "'"
                        + "  and a.aid=arrID "
                        + "  and a.aid=" + rs1.getInt(1));

                if (rs2.next()) {
                    to = rs2.getString(2) + " Airport (" + rs2.getString(3) + "), " + rs2.getString(4);
                }

            }
            rs1 = st1.executeQuery("select a.city "
                    + "from flight, airport a "
                    + "where flightno='" + flightno + "'"
                    + "  and a.aid in (depID,arrID) "
                    + "group by a.aid,a.city  "
                    + "having count(aid)=2");
            while (rs1.next()) {
                via += rs1.getString(1) + ", ";
            }

            if (via.equals("")) {
                via = "No Stops";
            } else {
                via = via.substring(0, via.length() - 2);
            }

            StatusTextArea.setText("FROM\t" + from);
            StatusTextArea.append("\nTO\t" + to);
            StatusTextArea.append("\nVIA\t" + via);
            StatusTextArea.append("\nSTATUS:\t" + status);

            con.close();
        } catch (SQLException se) {
            System.out.println(se);
        }


    }//GEN-LAST:event_CheckButtonActionPerformed