Beispiel #1
0
  public void DeleteHotelDb(HotelBean bean) {

    System.out.println(bean.getHotelId());
    int id = bean.getHotelId();
    System.out.println(id);

    Connection connection1 = null;
    try {
      System.out.println("yes");
      Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
      System.out.println("yes");
      connection1 =
          DriverManager.getConnection(
              "jdbc:oracle:thin:@172.16.68.55:1521:orcl1", "team5", "collabera");
      System.out.println("yes");
      PreparedStatement preparedStatementDelete =
          connection1.prepareStatement("DELETE FROM hotels WHERE hotel_id=?");
      preparedStatementDelete.setInt(1, id);
      int n = preparedStatementDelete.executeUpdate();
      System.out.println(n);

      if (n != 0) {
        bean.setFlag(true);
        System.out.println(bean.isFlag());
      } else {
        bean.setFlag(false);
        System.out.println(bean.isFlag());
      }
    } catch (Exception exception) {
      System.out.println(exception);
    }
  }
Beispiel #2
0
  public void EditHotelDb(HotelBean bean) {
    int id = bean.getHotelId(); //
    System.out.println(bean.getHotelId());

    Connection connection;
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
      connection =
          DriverManager.getConnection(
              "jdbc:oracle:thin:@172.16.68.55:1521:orcl1", "team5", "collabera");
      ResultSet rset;
      System.out.println("executed1");
      PreparedStatement preparedStatementEdit =
          connection.prepareStatement("SELECT * FROM hotels WHERE hotel_id=?");
      preparedStatementEdit.setInt(1, id);
      System.out.println("executed2");
      rset = preparedStatementEdit.executeQuery();
      System.out.println("executed3");

      if (rset == null) {
        bean.setFlag(false);
        System.out.println(bean.isFlag());
      } else if (rset != null) {

        while (rset.next()) {

          bean.setHotelId(rset.getInt(1)); //
          bean.setHotelName(rset.getString(2));
          bean.setDescription(rset.getString(3));
          bean.setLocation(rset.getString(4));
          bean.setRating(rset.getInt(5));
          bean.setRoomType(rset.getString(6));
          bean.setCostPerRoom(rset.getInt(7));
          bean.setFlag(true);
          System.out.println(bean.isFlag());

          System.out.println(bean.getHotelId());
          System.out.println(bean.getHotelName());
          System.out.println(bean.isFlag());
        }
      }

    } catch (Exception exception) {
      System.out.println(exception);
    }
  }
Beispiel #3
0
 public DbHotel(HotelBean hb) {
   this.hotelId1 = hb.getHotelId();
   this.hotelName1 = hb.getHotelName();
   this.description1 = hb.getDescription();
   this.location1 = hb.getLocation();
   this.rating1 = hb.getRating();
   this.roomType1 = hb.getRoomType();
   this.costPerRoom1 = hb.getCostPerRoom();
 }
Beispiel #4
0
  public void EditedHotelDb(HotelBean bean) {
    int id = bean.getHotelId(); //
    System.out.println("Id = " + id);
    System.out.println("yup");
    Connection connection = null;
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
      connection =
          DriverManager.getConnection(
              "jdbc:oracle:thin:@172.16.68.55:1521:orcl1", "team5", "collabera");
      System.out.println("yup");
      PreparedStatement preparedStatementAdd =
          connection.prepareStatement(
              "update hotels set hotel_name = ?,"
                  + "hotel_location=?,hotel_description=?,hotel_rating=?,room_type=?, cost_per_room=? where hotel_id = "
                  + id);

      /* System.out.println(bean.getPackageName());
      System.out.println(bean.getDestination());
      System.out.println(bean.getDescription());
      System.out.println(bean.getHotelId());
      System.out.println(bean.getNumOfDays());
      System.out.println(bean.getHolidayType());
      System.out.println(bean.getCostPerPerson());
      System.out.println(bean.getPackageId());*/

      preparedStatementAdd.setString(1, bean.getHotelName());
      preparedStatementAdd.setString(2, bean.getDescription());
      preparedStatementAdd.setString(3, (bean.getLocation()));
      preparedStatementAdd.setInt(4, (bean.getRating()));
      preparedStatementAdd.setString(5, bean.getRoomType());
      preparedStatementAdd.setInt(6, (bean.getCostPerRoom())); //
      System.out.println("yup");
      int n = preparedStatementAdd.executeUpdate();
      System.out.println(n);
      System.out.println("yup");
      if (n != 0) {
        System.out.println("true");
      } else {
        System.out.println("true");
      }
      preparedStatementAdd.close();

    } catch (Exception exception) {
      System.out.println(exception);
    }
  }
Beispiel #5
0
  public void bookkHotel(HotelBean hb) throws ClassNotFoundException, SQLException {
    this.hotelId1 = hb.getHotelId();
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection connection =
        DriverManager.getConnection(
            "jdbc:oracle:thin:@172.16.68.55:1521:orcl1", "team5", "collabera");
    // String str="select * from Hotelss where HOTEL_LOCATION=? and HOTEL_RATING=? and ROOM_TYPE=?";
    PreparedStatement stmt = connection.prepareStatement("select * from Hotels where HOTEL_ID=?");
    stmt.setInt(1, hotelId1);
    // int n=stmt.executeUpdate();
    // System.out.println(n);
    ResultSet rs1;
    rs1 = stmt.executeQuery();
    rs1.next();

    // System.out.println(rs1.getString(2));
    hb.setHotelName(rs1.getString(2));
    hb.setLocation(rs1.getString(3));
    hb.setRating(rs1.getInt(5));
    hb.setCostPerRoom(rs1.getInt(7));
    rs1.close();
    stmt.close();
    connection.close();
  }