示例#1
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);
    }
  }
示例#2
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();
  }