コード例 #1
0
 @Override
 public List<Booking> loadActiveBookingsByAccountId(Integer accountId) {
   Connection connect = null;
   PreparedStatement preparedStatement = null;
   ResultSet resultSet = null;
   // boolean isAuthenticated = false;
   List<Booking> bookings = new ArrayList<Booking>();
   // Date currentDate = new Date(new java.util.Date().getTime());
   try {
     connect = ConnectionPool.getPool().getConnection();
     preparedStatement = connect.prepareStatement(SELECT_BOOKINGS_BY_ACCOUNT_ID);
     preparedStatement.setInt(1, accountId);
     // preparedStatement.setDate(2, currentDate);
     // preparedStatement.setDate(3, currentDate);
     resultSet = preparedStatement.executeQuery();
     while (resultSet.next()) {
       Booking booking = new Booking();
       booking.setId(resultSet.getInt(BookingColumns.Id.getName()));
       booking.setRoomId(resultSet.getInt(BookingColumns.roomId.getName()));
       booking.setCheckinDate(resultSet.getDate(BookingColumns.checkinDate.getName()));
       booking.setCheckoutDate(resultSet.getDate(BookingColumns.checkoutDate.getName()));
       System.out.println(booking.getId());
       System.out.println(booking.getRoomId());
       System.out.println(booking.getCheckinDate());
       System.out.println(booking.getCheckoutDate());
       bookings.add(booking);
     }
   } catch (Exception e) {
     throw new DAOException(e);
   } finally {
     ConnectionPool.releaseConnection(connect, preparedStatement, resultSet);
   }
   return bookings;
 }
コード例 #2
0
 @Override
 public void saveBooking(Booking booking) throws DAOException {
   Connection connect = null;
   PreparedStatement preparedStatement = null;
   ResultSet resultSet = null;
   try {
     connect = ConnectionPool.getPool().getConnection();
     preparedStatement = connect.prepareStatement(SAVE_BOOKING);
     // preparedStatement.setInt(1, booking.getId());
     preparedStatement.setInt(1, booking.getRoomId());
     preparedStatement.setInt(2, booking.getAccountId());
     Date orderDate = new Date(booking.getCheckinDate().getTime());
     preparedStatement.setDate(3, orderDate);
     Date checkinDate = new Date(booking.getCheckinDate().getTime());
     preparedStatement.setDate(4, checkinDate);
     Date checkoutDate = new Date(booking.getCheckoutDate().getTime());
     preparedStatement.setDate(5, checkoutDate);
     preparedStatement.executeUpdate();
   } catch (Exception e) {
     throw new DAOException(e);
   } finally {
     ConnectionPool.releaseConnection(connect, preparedStatement, resultSet);
   }
 }