Esempio n. 1
0
  public int saveGuest(Person p, Guest g) throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Saving guest...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();

      int idPerson = p.getId();

      String guestFirstname = g.getFirstname();
      String guestMiddlename = g.getMiddlename();
      String guestLastname = g.getLastname();
      String guestBirthday = ADate.formatADate(g.getBirthday(), "");
      String guestCreationdate = ADate.formatADate(g.getCreationDate(), "");

      s.execute(
          "INSERT INTO guest (firstname, middlename, lastname, creationdate, birthday, idperson) VALUES('"
              + guestFirstname
              + "', '"
              + guestMiddlename
              + "', '"
              + guestLastname
              + "', '"
              + guestCreationdate
              + "', '"
              + guestBirthday
              + "', '"
              + idPerson
              + "');");
      ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID();");
      rs.next();
      int returnId = rs.getInt(1);
      System.out.println("Save complete!");
      rs.close();
      s.close();
      conn.close();
      return returnId;
    } else {
      System.out.println("Connection not valid");
      conn.close();
      return -1;
    }
  }
Esempio n. 2
0
  public int insertPerson(Person p) throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Inserting person...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();

      String firstname = p.getFirstname();
      String middlename = p.getMiddlename();
      String lastname = p.getLastname();
      String address = p.getAddress();
      String birthday = ADate.formatADate(p.getBirthdayDate(), "");
      String expirationDate = ADate.formatADate(p.getExpirationDate(), "");
      File picturePathF = p.getPicturePath();
      String picturePath = FileTool.getDefaultFolder() + "/" + picturePathF.getName();
      int quarantine = 0;
      String quarantineExpirationDate = "";
      if (p.getQuarantineExpirationDate() != null) {
        quarantineExpirationDate = p.getQuarantineExpirationDate().toString();
      }
      int oneOne = 0;
      String creationDate = ADate.formatADate(p.getCreationDate(), "");
      if (p.isQuarantine()) {
        quarantine = 1;
      }
      if (p.isOneOne()) {
        oneOne = 1;
      }
      int enrolled = 0;
      if (p.isEnrolled()) {
        enrolled = 1;
      }
      int hone = 0;
      if (p.isHone()) {
        hone = 1;
      }

      s.executeUpdate(
          "INSERT INTO person (firstname, middlename, lastname, address, birthday, expirationdate, picturepath, quarantine, quarantineexpirationdate, oneone, creationdate, enrolled, hone) "
              + "VALUES('"
              + firstname
              + "', '"
              + middlename
              + "', '"
              + lastname
              + "', '"
              + address
              + "', '"
              + birthday
              + "', '"
              + expirationDate
              + "', '"
              + picturePath
              + "', '"
              + quarantine
              + "', '"
              + quarantineExpirationDate
              + "', '"
              + oneOne
              + "', '"
              + creationDate
              + "', '"
              + enrolled
              + "', '"
              + hone
              + "');");
      ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID();");
      rs.next();
      int idback = rs.getInt(1);
      System.out.println("Insertion complete!");
      rs.close();
      s.close();
      conn.close();
      return idback;
    } else {
      System.out.println("Connection not valid");
      conn.close();
      return -1;
    }
  }
Esempio n. 3
0
  public void savePerson(Person p) throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Saving person...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();

      int idperson = p.getId();
      String firstname = p.getFirstname();
      String middlename = p.getMiddlename();
      String lastname = p.getLastname();
      String address = p.getAddress();
      String birthday = ADate.formatADate(p.getBirthdayDate(), "");
      String expirationDate = ADate.formatADate(p.getExpirationDate(), "");
      File picturePathF = p.getPicturePath();
      String picturePath = FileTool.getDefaultFolder() + "/" + picturePathF.getName();
      int quarantine = 0;
      String quarantineExpirationDate = "";
      if (p.getQuarantineExpirationDate() != null) {
        quarantineExpirationDate = p.getQuarantineExpirationDate().toString();
      }
      int oneOne = 0;
      if (p.isQuarantine()) {
        quarantine = 1;
      }
      if (p.isOneOne()) {
        oneOne = 1;
      }
      int enrolled = 0;
      if (p.isEnrolled()) {
        enrolled = 1;
      }
      int hone = 0;
      if (p.isHone()) {
        hone = 1;
      }

      s.executeUpdate(
          "UPDATE person SET firstname = '"
              + firstname
              + "', middlename = '"
              + middlename
              + "', lastname = '"
              + lastname
              + "', address = '"
              + address
              + "', birthday = '"
              + birthday
              + "', expirationdate = '"
              + expirationDate
              + "', picturepath = '"
              + picturePath
              + "', oneone = "
              + oneOne
              + ", quarantine = "
              + quarantine
              + ", enrolled = "
              + enrolled
              + ", hone= "
              + hone
              + " WHERE idperson = "
              + idperson
              + ";");
      System.out.println("Save complete!");
      s.close();
      conn.close();
    } else {
      System.out.println("Connection not valid");
      conn.close();
    }
  }