public AbsentTeacher(int id, String name, String subject, String classes, String day) {
    this.id = id;
    this.name = name;
    this.subject = subject;
    this.day = day;
    String query =
        "SELECT zero,first,second,third,fourth,fifth,sixth,seventh,eight "
            + "FROM timetbl WHERE day = '"
            + this.day
            + "' AND teach_id = "
            + this.id
            + " ;";

    ResultSet rs = MySQL.query(query);
    try {
      while (rs.next()) {
        this.timeTable[0] = rs.getString("zero");
        this.timeTable[1] = rs.getString("first");
        this.timeTable[2] = rs.getString("second");
        this.timeTable[3] = rs.getString("third");
        this.timeTable[4] = rs.getString("fourth");
        this.timeTable[5] = rs.getString("fifth");
        this.timeTable[6] = rs.getString("sixth");
        this.timeTable[7] = rs.getString("seventh");
        this.timeTable[8] = rs.getString("eight");
      }
    } catch (SQLException ex) {
      JOptionPane.showMessageDialog(null, "here");
    }
  }
Esempio n. 2
0
 public boolean Connect() {
   try {
     setConnectionReport(_connect.getConnect());
     return true;
   } catch (Exception ex) {
     Logger.getLogger(ConnectUnit.class.getName()).log(Level.SEVERE, null, ex);
     return false;
   }
 }
 public void checkStatus(int i) {
   String query =
       "update teachers,timetbl set teachers.status=0 where teachers.id=timetbl.teach_id and timetbl."
           + this.period[i]
           + " is not null and day = '"
           + this.day
           + "';";
   MySQL.update(query);
 }
Esempio n. 4
0
 // Hàm hỗ trợ Select CSDL
 // SELECT * FORM TableName WHERE Condition ORDER BY OrderBy;
 public ResultSet Select(String TableName, String Condition, String OrderBy) throws Exception {
   // Khai báo biến StringBuilder để tạo chuỗi Select.
   StringBuilder query = new StringBuilder("SELECT * FROM " + TableName);
   // Đưa câu lệnh điều kiện vào trong câu query
   this.AddCondition(query, Condition);
   // Đưa câu lệnh Order vào câu query
   this.AddOrderBy(query, OrderBy);
   // Chèn ký tự ';' vào cuối dòng lệnh của để cách các câu lệnh.
   query.append(";");
   // Thực thi câu query và trả kết quả ra ngoài
   return _connect.excuteQuery(query.toString());
 }
Esempio n. 5
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("application/json");
    PrintWriter out = response.getWriter();

    request.setCharacterEncoding("UTF-8");
    session = request.getSession();
    if (session.getAttribute("userid") == null) {
      response.sendRedirect("index.jsp");
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
    String json = "{}";
    if (br != null) {
      json = br.readLine();
    }

    try {
      JSONObject req = new JSONObject(URLDecoder.decode(json, "UTF-8"));
      con = new MySQLConnect("localhost", "docflow", "3306", "writer", "1");
      PreparedStatement prep = null;
      prep =
          con.getConnection()
              .prepareStatement(
                  "INSERT INTO "
                      + "sprfiz(`id`, `name`,`regdate`, `homeadres`,`rabadres`,`tel`,`Email`,`workname`,`post`,`komment`)"
                      + " VALUES  (NULL,?,NOW(),?,?,?,?,?,?,?)");
      prep.setString(1, req.getString("name"));
      prep.setString(2, req.getString("homeadres"));
      prep.setString(3, req.getString("rabadres"));
      prep.setString(4, req.getString("tel"));
      prep.setString(5, req.getString("Email"));
      prep.setString(6, req.getString("workname"));
      prep.setString(7, req.getString("post"));
      prep.setString(8, req.getString("komment"));
      prep.executeUpdate();
      JSONObject output = new JSONObject();
      output.accumulate("status", "success");
      out.println(output.toString());
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      out.close();
    }
  }
  public void findTeachers(int period) {
    String query1, query2, query3, query4;
    String classSec = this.timeTable[period];
    String classOnly = this.getClassOnly(this.timeTable[period]);
    String secOnly = this.getSecOnly(this.timeTable[period]);
    this.checkStatus(period);
    query1 =
        "SELECT teach_name FROM teachers WHERE status = 1 AND atendence = 1 AND  "
            + "classes LIKE '%("
            + classSec
            + ")%' ORDER BY RAND() LIMIT 1;";
    query2 =
        "SELECT teach_name FROM teachers WHERE status = 1 AND atendence = 1 AND "
            + "classes LIKE '%("
            + classOnly
            + "_)%' AND subject = '"
            + this.subject
            + "' ORDER BY RAND() LIMIT 1;";
    query3 =
        "SELECT teach_name FROM teachers WHERE status = 1 AND atendence = 1 AND "
            + "subject = '"
            + this.subject
            + "' ORDER BY RAND() LIMIT 1;";
    query4 =
        "SELECT teach_name FROM teachers WHERE status = 1 AND atendence = 1 ORDER BY RAND() LIMIT 1;";

    try {
      String query;
      ResultSet rs1 = MySQL.query(query1);
      ResultSet rs2 = MySQL.query(query2);
      ResultSet rs3 = MySQL.query(query3);
      ResultSet rs4 = MySQL.query(query4);
      if (rs1.next()) {
        this.setChart(period, rs1.getString("teach_name"));
        query =
            "UPDATE teachers Set status = 0 WHERE teach_name = '"
                + rs1.getString("teach_name")
                + "';";
        MySQL.update(query);
        rs1.close();
      } else if (rs2.next()) {
        this.setChart(period, rs2.getString("teach_name"));
        query =
            "UPDATE teachers Set status = 0 WHERE teach_name = '"
                + rs2.getString("teach_name")
                + "';";
        MySQL.update(query);

      } else if (rs3.next()) {
        this.setChart(period, rs3.getString("teach_name"));
        query =
            "UPDATE teachers Set status = 0 WHERE teach_name = '"
                + rs3.getString("teach_name")
                + "';";
        MySQL.update(query);
      } else if (rs4.next()) {
        this.setChart(period, rs4.getString("teach_name"));
        query =
            "UPDATE teachers Set status = 0 WHERE teach_name = '"
                + rs4.getString("teach_name")
                + "';";
        MySQL.update(query);
      } else {
        this.setChart(period, "PE");
        System.out.println("PE LAG ");
      }
    } catch (SQLException ex) {
      System.out.println(ex + "sfdsfd");
      JOptionPane.showMessageDialog(null, ex);
    }
  }
Esempio n. 7
0
 private void formWindowOpened(
     java.awt.event.WindowEvent evt) { // GEN-FIRST:event_formWindowOpened
   conn = MySQLConnect.ConnectDB();
 } // GEN-LAST:event_formWindowOpened