コード例 #1
0
 /**
  * @param index
  * @throws SQLException
  */
 public void remove(int index) throws SQLException {
   Connection connection = MySQLDatabase.getConnection();
   PreparedStatement preparedStatement = connection.prepareStatement(DB_DELETE_REQUEST);
   preparedStatement.setInt(1, index);
   preparedStatement.executeUpdate();
   MySQLDatabase.releaseConnection(connection);
 }
コード例 #2
0
 /**
  * @return amount of requests
  * @throws SQLException
  */
 public Integer getAmountOfRequests() throws SQLException {
   Connection c = MySQLDatabase.getConnection();
   PreparedStatement s = c.prepareStatement(DB_AMOUNT_REQUESTS);
   ResultSet rs = s.executeQuery();
   int amount = 0;
   if (rs.next()) {
     amount = rs.getInt(ColumnNames.AMOUNT);
   }
   MySQLDatabase.releaseConnection(c);
   return amount;
 }
コード例 #3
0
 /**
  * @param index
  * @return get different between dates in database
  * @throws SQLException
  */
 public Integer getDateDiff(int index) throws SQLException {
   Connection c = MySQLDatabase.getConnection();
   PreparedStatement s = c.prepareStatement(DB_GET_DATE_DIFF);
   s.setInt(1, index);
   ResultSet rs = s.executeQuery();
   if (rs.next()) {
     return rs.getInt(ColumnNames.DIFF);
   }
   MySQLDatabase.releaseConnection(c);
   return null;
 }
コード例 #4
0
 /**
  * @return list of requests
  * @throws SQLException
  */
 public List<RequestRoom> getAll() throws SQLException {
   Connection c = MySQLDatabase.getConnection();
   PreparedStatement s = c.prepareStatement(DB_GET_ALL_REQUESTS);
   ResultSet rs = s.executeQuery();
   List<RequestRoom> result = new ArrayList<>();
   while (rs.next()) {
     result.add(getRequestRoom(rs));
   }
   MySQLDatabase.releaseConnection(c);
   return result;
 }
コード例 #5
0
 /**
  * @param from
  * @param amount
  * @return list of requests
  * @throws SQLException
  */
 public List<RequestRoom> getRequests(int from, int amount) throws SQLException {
   Connection c = MySQLDatabase.getConnection();
   String str = DB_GET_ALL_REQUESTS + " limit " + from + ", " + amount;
   PreparedStatement s = c.prepareStatement(str);
   ResultSet rs = s.executeQuery();
   List<RequestRoom> result = new ArrayList<>();
   while (rs.next()) {
     result.add(getRequestRoom(rs));
   }
   MySQLDatabase.releaseConnection(c);
   return result;
 }
コード例 #6
0
 /**
  * @param request
  * @throws SQLException
  */
 public void add(RequestRoom request) throws SQLException {
   Connection connection = MySQLDatabase.getConnection();
   String arrival = "cast(N'" + request.getArrivalDate() + "' as DateTime)";
   String departure = "cast(N'" + request.getDepartureDate() + "' as DateTime)";
   String url = String.format(DB_INSERT_REQUEST, arrival, departure);
   PreparedStatement preparedStatement = connection.prepareStatement(url);
   preparedStatement.setInt(1, request.getId());
   preparedStatement.setInt(2, request.getAmountOfBed());
   preparedStatement.setString(3, request.getClassOfRoom());
   preparedStatement.setInt(4, request.getClient().getUser().getId());
   preparedStatement.executeUpdate();
   MySQLDatabase.releaseConnection(connection);
 }
コード例 #7
0
 /**
  * @param id
  * @return object RequestRoom
  * @throws SQLException
  */
 public RequestRoom get(Integer id) throws SQLException {
   Connection c = MySQLDatabase.getConnection();
   PreparedStatement s = c.prepareStatement(DB_GET_REQUEST);
   s.setInt(1, id);
   ResultSet rs = s.executeQuery();
   RequestRoom requestRoom = new RequestRoom();
   if (rs.next()) {
     requestRoom.setId(id);
     requestRoom.setClassOfRoom(rs.getString(ColumnNames.CLASS));
     requestRoom.setAmountOfBed(rs.getInt(ColumnNames.AMOUNT_OF_BED));
     requestRoom.setDepartureDate(rs.getDate(ColumnNames.DEPARTURE_DATE));
     requestRoom.setArrivalDate(rs.getDate(ColumnNames.ARRIVAL_DATE));
     Client client = new Client();
     User user = new User();
     user.setId(rs.getInt(ColumnNames.USER_ID));
     client.setUser(user);
     requestRoom.setClient(client);
   }
   MySQLDatabase.releaseConnection(c);
   return requestRoom;
 }