/* (non-Javadoc)
   * @see assn2.daos.RecordDAO#getAllByUser(int)
   */
  @Override
  public List<RecordBean> getAllByHotel(int id) throws DataAccessException {
    Connection conn = null;
    List<RecordBean> list = new ArrayList<RecordBean>();
    try {
      conn = services.createConnection();
      PreparedStatement stmt = conn.prepareStatement("select * from Record where hotelid = ? ");
      stmt.setInt(1, id);

      ResultSet rs = stmt.executeQuery();
      if (rs == null) // remember to catch the exceptions
      throw new DataAccessException("cannot find entity of that userid");
      while (rs.next()) {
        RecordBean r = createRecordBean(rs);
        list.add(r);
      }
    } catch (ServiceLocatorException e) {
      e.printStackTrace(); // no connection
    } catch (SQLException e) {
      e.printStackTrace(); // not execution of statement
    } finally {
      if (conn != null) {
        try {
          conn.close(); // and close the connections etc
        } catch (SQLException e1) { // if not close properly
          e1.printStackTrace();
        }
      }
    }
    return list;
  }
 /** Creates a new instance of RecordDAOImpl */
 public RecordDAOImpl() {
   try {
     services = new DBConnectionFactory();
   } catch (ServiceLocatorException e) {
     e.printStackTrace();
   }
 }
  /* (non-Javadoc)
   * @see assn2.daos.RecordDAO#getRecord(int)
   */
  @Override
  public RecordBean getRecord(int id) throws DataAccessException {
    Connection conn = null;
    try {
      conn = services.createConnection();
      PreparedStatement stmt = conn.prepareStatement("select * from Record where recordid = ? ");
      stmt.setInt(1, id);

      ResultSet rs = stmt.executeQuery();
      if (rs == null) // remember to catch the exceptions
      throw new DataAccessException("cannot find entity of that recordid");
      if (rs.next()) {
        RecordBean r = createRecordBean(rs);
        stmt.close(); // close it
        return r;
      }
    } catch (ServiceLocatorException e) {
      e.printStackTrace(); // no connection
    } catch (SQLException e) {
      e.printStackTrace(); // not execution of statement
    } finally {
      if (conn != null) {
        try {
          conn.close(); // and close the connections etc
        } catch (SQLException e1) { // if not close properly
          e1.printStackTrace();
        }
      }
    }
    return null; // not found
  }
  public int getUserid(int recordid) {
    Connection conn = null;
    int r = -1;
    try {
      conn = services.createConnection();
      PreparedStatement stmt =
          conn.prepareStatement(
              "select * from Record as r, Booking as b where r.bookingid = b.bookingid AND r.recordid = (?) ");
      stmt.setInt(1, recordid);

      ResultSet rs = stmt.executeQuery();
      if (rs == null) // remember to catch the exceptions
      throw new DataAccessException("cannot find entity of that recordid");
      rs.next();
      r = rs.getInt("userid");
      return r;
    } catch (ServiceLocatorException e) {
      e.printStackTrace(); // no connection
    } catch (SQLException e) {
      e.printStackTrace(); // not execution of statement
    } finally {
      if (conn != null) {
        try {
          conn.close(); // and close the connections etc
        } catch (SQLException e1) { // if not close properly
          e1.printStackTrace();
        }
      }
    }
    return r;
  }