コード例 #1
0
 public static boolean update(String c, String bid) {
   Connection conn = DB.getConn();
   String sql = "update mdgrouptype set gname = ? where id = " + bid;
   PreparedStatement pstmt = DB.prepare(conn, sql);
   try {
     pstmt.setString(1, c);
     pstmt.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     DB.close(pstmt);
     DB.close(conn);
   }
   return true;
 }
コード例 #2
0
 public static boolean save(String c) {
   Connection conn = DB.getConn();
   String sql = "insert into mdgrouptype(id,gname,statues) values (null, ?,?)";
   PreparedStatement pstmt = DB.prepare(conn, sql);
   try {
     pstmt.setString(1, c);
     pstmt.setInt(2, 0);
     pstmt.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     DB.close(pstmt);
     DB.close(conn);
   }
   return true;
 }
コード例 #3
0
  /**
   * Handles the HTTP <code>GET</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String destination = "changePass.jsp";
    HttpSession s = request.getSession();
    String sessionEmail = (String) s.getAttribute("email");
    System.out.println("entered  change password, session mail = " + sessionEmail);

    if ((String) s.getAttribute("emailToBeModified") != null) {
      System.out.println("entered  change passwordemail param!= null");
      emailToBeModified = (String) s.getAttribute("emailToBeModified");
      System.out.println("emailtobemodified :" + emailToBeModified);
    }

    if (!sessionEmail.equals(emailToBeModified)) {
      System.out.println(
          "entered email to modify :  != email : " + emailToBeModified + " / " + sessionEmail);
      isAdmin = "true";
    } else {
      isAdmin = "false";
      System.out.println(
          "entered email to modify = session email : " + emailToBeModified + " / " + sessionEmail);

      oldpwd = dbmanager.getPassword(emailToBeModified);
    }
    request.setAttribute("isAdmin", isAdmin);
    System.out.println(" go to jsp");

    request.setAttribute("emailToBeModified", emailToBeModified);
    RequestDispatcher rd = request.getRequestDispatcher("/" + destination);
    rd.forward(request, response);
  }
コード例 #4
0
ファイル: DB.java プロジェクト: ruiG/SDIS
  /**
   * Main para testar a base de dados
   *
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    DB database = new DB("db");
    database.addFile("1ijfj2382u5m98u85u2", "bino.jpg", 3);
    database.addFile("3jf92rf28ur2mu24umr", "lel.gif", 5);
    database.addFile("jf29r924r9249ru29ru", "OMG.png", 10);
    System.out.println(database.getChunkNumberbyFileID("1ijfj2382u5m98u85u2"));
    System.out.println(database.getFileNamebyFileID("1ijfj2382u5m98u85u2"));
    System.out.println(database.getFileIDbyFileName("lel.gif"));
    String bla = database.getFileIDbyFileName("lel.gif");
    if (bla == null) System.out.println("NOPE");

    database.close();
  }
コード例 #5
0
  public static List<Grouptype> getGroup(User user) {

    List<Grouptype> users = new ArrayList<Grouptype>();
    Connection conn = DB.getConn();
    String sql = "";
    if (UserManager.checkPermissions(user, Group.Manger)) {
      sql = "select * from mdgrouptype ";
    } else {
      sql = "select * from mdgrouptype ";
    }

    Statement stmt = DB.getStatement(conn);
    ResultSet rs = DB.getResultSet(stmt, sql);
    try {
      while (rs.next()) {
        Grouptype g = GrouptypeManager.getGroupFromRs(rs);
        users.add(g);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      DB.close(rs);
      DB.close(stmt);
      DB.close(conn);
    }
    return users;
  }
コード例 #6
0
ファイル: InputChecker.java プロジェクト: Dave0408/bims2015
  public static boolean nameAdresseExist(String name, String adresse, String plz)
      throws SQLException {

    if (adresse == null) {
      adresse = "";
    }
    if (plz == null) {
      plz = "";
    }
    if (name == null) {
      name = "";
    }
    String sqlNamePLZAdresse =
        "select * from locations where straßenname = '"
            + adresse
            + "' "
            + "and PLZ = '"
            + plz
            + "' and Name = '"
            + name
            + "'";
    ResultSet resultSet0 = db.runSql(sqlNamePLZAdresse);
    if (!resultSet0.next()) {
      String sqlNameAdresse =
          "select * from locations where straßenname = '"
              + adresse
              + "' "
              + "and  Name = '"
              + name
              + "'";
      ResultSet resultSet1 = db.runSql(sqlNameAdresse);
      if (!resultSet1.next()) {
        return false;
      } else {
        return true;
      }
    } else {
      return true;
    }
  }
コード例 #7
0
ファイル: InputChecker.java プロジェクト: Dave0408/bims2015
 public static boolean idExist(String id, String api) throws SQLException {
   String sql0 =
       "select * from locations where ID_Plattform = '"
           + id
           + "' "
           + "and Quell_Plattform = '"
           + api
           + "'";
   ResultSet resultSet0 = db.runSql(sql0);
   if (resultSet0.next()) {
     return true;
   }
   return false;
 }
コード例 #8
0
  public static int delete(User user, String ptype) {

    List<Group> list = GroupManager.getGroup(user, Integer.valueOf(ptype));

    List<Group> listg = GroupManager.getGroupdown(user, Integer.valueOf(ptype), 1);

    if (list != null && list.size() > 0 || listg != null && listg.size() > 0) {
      return -1;
    }

    int count = 0;
    Connection conn = DB.getConn();
    String sql = "delete from mdgrouptype where id = " + ptype;
    logger.info(sql);
    Statement stmt = DB.getStatement(conn);

    try {
      count = DB.executeUpdate(stmt, sql);
    } finally {
      DB.close(stmt);
      DB.close(conn);
    }
    return count;
  }
コード例 #9
0
ファイル: SignupServlet.java プロジェクト: CHAIBHANGALE/APIS
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // Set header Content-type of the HttpResponse
    // Read more here. https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
    response.setContentType("application/json");
    // For accepting cross domain requests
    response.addHeader("Access-Control-Allow-Origin", "*");
    response.addHeader("Access-Control-Allow-Methods", "GET, PUT, POST, OPTIONS, DELETE");
    response.addHeader("Access-Control-Allow-Headers", "Content-Type");

    // get email by get method
    String email = request.getParameter(Signup.EMAIL);
    if (email == null || email.equals("")) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Field 'email' required");
      return;
    }

    // get password by get method
    String password = request.getParameter(Signup.PASSWORD);

    if (password == null || password.equals("")) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Field required");
      return;
    }

    try {
      Signup signup = new Signup(email, password);
      // insert a single value in database
      String _id = DB.insertValue(signup);
      // creating a json object and put the id of data inserted into it
      JSONObject jsonResponse = new JSONObject();
      jsonResponse.put(Signup.ID, _id);

      // function to print the id ie return response
      response.getWriter().write(jsonResponse.toString());
    }

    // if input output erroroccurs due to database
    catch (IOException | JSONException e) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
      e.printStackTrace();
    }
  }
コード例 #10
0
ファイル: InputChecker.java プロジェクト: Dave0408/bims2015
 public static boolean partyphaseEventExist(String datum, String location, String text)
     throws SQLException {
   String sql1 =
       "SELECT * FROM `crawler`.`crawl_events` "
           + "WHERE `crawl_events`.`datum`='"
           + datum
           + "' "
           + "AND `crawl_events`.`name`='"
           + location
           + "' "
           + "AND `crawl_events`.`text`='"
           + text
           + "' ";
   ResultSet resultSet0 = db.runSql(sql1);
   if (resultSet0.next()) {
     return true;
   }
   return false;
 }
コード例 #11
0
ファイル: InputChecker.java プロジェクト: Dave0408/bims2015
  public static boolean msmarketingEventExist(
      String datum, String location, String titel, String uhrzeit) throws SQLException {

    String sql1 =
        "SELECT * FROM `crawler`.`crawl_events` "
            + "WHERE `crawl_events`.`datum`='"
            + datum
            + "' "
            + "AND `crawl_events`.`uhrzeit`='"
            + uhrzeit
            + "' "
            + "AND `crawl_events`.`name`='"
            + location
            + "' "
            + "AND `crawl_events`.`titel`='"
            + titel
            + "' ";
    ResultSet resultSet0 = db.runSql(sql1);
    if (resultSet0.next()) {
      return true;
    }
    return false;
  }
コード例 #12
0
 public static Grouptype getGrouptype(int id) {
   Grouptype g = new Grouptype();
   Connection conn = DB.getConn();
   String sql = "select * from mdgrouptype where id = " + id;
   Statement stmt = DB.getStatement(conn);
   ResultSet rs = DB.getResultSet(stmt, sql);
   try {
     while (rs.next()) {
       g = GrouptypeManager.getGroupFromRs(rs);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     DB.close(rs);
     DB.close(stmt);
     DB.close(conn);
   }
   return g;
 }
コード例 #13
0
 public static int getgrouptype(int id) {
   int type = 0;
   Connection conn = DB.getConn();
   String sql = "select * from mdgrouptype where type = " + id;
   Statement stmt = DB.getStatement(conn);
   ResultSet rs = DB.getResultSet(stmt, sql);
   try {
     while (rs.next()) {
       Grouptype branch = getGroupFromRs(rs);
       type = branch.getId();
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     DB.close(rs);
     DB.close(stmt);
     DB.close(conn);
   }
   return type;
 }
コード例 #14
0
/** @author Ahmad Naufal Farhan */
public class VoteQuestion extends HttpServlet {

  Connection conn = DB.getConnection();
  /**
   * 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("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
      /* TODO output your page here. You may use following sample code. */
      out.println("<!DOCTYPE html>");
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet Vote</title>");
      out.println("</head>");
      out.println("<body>");
      out.println("<h1>Servlet Vote at " + request.getContextPath() + "</h1>");
      out.println("</body>");
      out.println("</html>");
    }
  }

  // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the
  // left to edit the code.">
  /**
   * Handles the HTTP <code>GET</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // processRequest(request, response);
    int res = 0;
    JSONObject obj = new JSONObject();

    try (PrintWriter out = response.getWriter()) {

      int qid = Integer.parseInt(request.getParameter("qid"));
      String query = "SELECT value FROM vote_questions WHERE qid = ?";

      // set the prepared statement by the query and enter the value of where clause
      try (PreparedStatement pst = conn.prepareStatement(query)) {
        pst.setInt(1, qid);
        // execuResultSette select
        ResultSet ret = pst.executeQuery();
        while (ret.next()) {
          res += ret.getInt("value");
        }
      }

      // put the results
      obj.put("success", 1);
      obj.put("qid", qid);
      obj.put("value", res);

      out.print(obj);

    } catch (SQLException ex) {
      Logger.getLogger(VoteQuestion.class.getName()).log(Level.SEVERE, null, ex);
    }
  }

  /**
   * Handles the HTTP <code>POST</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO write your implementation code here:
    String token = request.getParameter("token");
    int qid = Integer.parseInt(request.getParameter("qid"));
    int value = Integer.parseInt(request.getParameter("value"));
    String ipAddress = request.getParameter("ipaddress");
    String useragent = request.getParameter("uagent");

    JSONObject obj = new JSONObject();

    int res = Validation.AUTH_INVALID; // initialize result with error first (assumption)
    long user_id =
        Validation.validateToken(token, ipAddress, useragent); // validate token and get the user id

    try (PrintWriter out = response.getWriter()) {
      // token is valid if user_id value is not -1
      if (user_id != -1) {

        try (Statement st = conn.createStatement()) {
          String query = "SELECT * FROM `vote_questions` WHERE uid = ? AND qid = ?";
          try (PreparedStatement pstselect = conn.prepareStatement(query)) {
            pstselect.setLong(1, user_id);
            pstselect.setInt(2, qid);
            // execute select
            ResultSet ret = pstselect.executeQuery();
            if (!ret.next()) {
              query = "INSERT INTO `vote_questions` (uid, qid, value) VALUES (?, ?, ?)";

              // set the prepared statement by the query and enter the value of where clause
              try (PreparedStatement pst = conn.prepareStatement(query)) {
                pst.setLong(1, user_id);
                pst.setInt(2, qid);
                pst.setInt(3, value);
                // execute update
                res = pst.executeUpdate();
                if (res > 0) res = Validation.AUTH_VALID;
              }
            }
          }

        } catch (SQLException ex) {
          Logger.getLogger(VoteAnswers.class.getName()).log(Level.SEVERE, null, ex);
        }
      } else {
        // else: token is invalid, deny request
        res = Validation.AUTH_INVALID;
      }

      obj.put("success", res);
      out.print(obj);
    }
  }

  /**
   * Returns a short description of the servlet.
   *
   * @return a String containing servlet description
   */
  @Override
  public String getServletInfo() {
    return "Short description";
  } // </editor-fold>
}
コード例 #15
0
  /**
   * Handles the HTTP <code>POST</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // processRequest(request, response);
    String destination = "";
    System.out.println("entered  change password POST");
    HttpSession s = request.getSession();
    // Get the parameters to change password
    String apwd = "";
    String npwd = request.getParameter("npwd");
    String rnpwd = request.getParameter("rnpwd");

    if (isAdmin.equals("true")) {
      destination = "management.jsp";
      // si on est admin on a que le nouveau et sa répétition à tester
      System.out.println("entered  change password POST - is admin true !");
      if (npwd.length() < 8) {
        // si longueur du mdp < 8 : erreur
        s.setAttribute("msgErreur", "Mot de passe doit contenir au moins 8 caractères.");
        System.out.println("New Password not correct!");
      } else {
        if (!npwd.equals(rnpwd)) {
          // si le password n'est pas correctement répété : erreur
          s.setAttribute("msgErreur", "Veuillez entrer le même mot de passe deux fois.");
          System.out.println("Please enter the same password twice!");
        } else {
          System.out.println(
              "entered  change password POST - is admin true password correct -> query");
          dbmanager.setPassword(emailToBeModified, npwd);
        }
      }

    } else {
      // si c'est pas l'admin qui change le mdp alors c'est un utilisateur ( qui peut etre admin à
      // noter )
      // mais dans tous les cas il doit connaitre son ancien mdp
      System.out.println("entered  change password POST - not admin request !");
      destination = "userWelcome.jsp";
      apwd = (String) request.getParameter("apwd");

      if (!oldpwd.equals(apwd)) {
        s.setAttribute("msgErreur", "Ancien mot de passe incorrect!");
        System.out.println("Old Password not correct!");
      } else {
        System.out.println("old password is correct");
        if (npwd.length() < 8) {
          // si longueur du mdp < 8 : erreur
          s.setAttribute("msgErreur", "Mot de passe doit contenir au moins 8 caractères.");
          System.out.println("New Password not correct!");
        } else {
          if (!npwd.equals(rnpwd)) {
            // si le password n'est pas correctement répété : erreur
            s.setAttribute("msgErreur", "Veuillez entrer le même mot de passe deux fois.");
            System.out.println("Please enter the same password twice!");
          } else {
            System.out.println("old password is correct , new password are correct - > query");
            dbmanager.setPassword(emailToBeModified, npwd);
          }
        }
      }
    }

    final RequestDispatcher rd = request.getRequestDispatcher("/" + destination);
    rd.forward(request, response);
  }