This is a console-based Hotel Reservation Management System built using
Java, JDBC, and MySQL. It allows hotel staff to
manage room reservations efficiently with a simple text-based interface.
The main Java file HotelReservationSystem.java is located in the src/ directory of the project.
- Create new room reservations.
- View all current reservations in a formatted table.
- Retrieve room number by reservation ID and guest name.
- Update reservation details (name, room number, contact).
- Delete a reservation by ID.
- Simple menu-driven CLI interface.
- MySQL integration using JDBC.
- Timestamp auto-generation for reservation date.
Technology | Description |
---|---|
Java | Programming language used |
JDBC | Java Database Connectivity API |
MySQL | Relational database for storing reservation data |
IntelliJ / Eclipse | Recommended IDE for development |
Create the following table in your MySQL database:
CREATE DATABASE IF NOT EXISTS hotel_db;
USE hotel_db;
CREATE TABLE IF NOT EXISTS reservations ( reservation_id INT AUTO_INCREMENT PRIMARY KEY, guest_name VARCHAR(255) NOT NULL, room_num INT NOT NULL, contact_num VARCHAR(20) NOT NULL, reservation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
- Clone this repository or download the source code.
- Set up MySQL database:
- Run the SQL script above.
- Make sure MySQL is running locally on port 3306.
- Update DB credentials in the code:
In HotelReservationSystem.java:
private static final String url = "jdbc:mysql://localhost:3306/hotel_db";
private static final String username = "your_mysql_username";
private static final String password = "your_mysql_password";
- Add JDBC MySQL driver to your project:
- Download the MySQL Connector JAR.
- Add it to your projectโs classpath (in IntelliJ: File โ Project Structure โ Libraries).
- Compile and Run the Program:
- From your IDE or using
javac
andjava
commands.
- From your IDE or using
- Reserve a Room
- Input guest name, room number, and contact number.
- Saves the reservation to the database.
- View Reservations
- Lists all reservations in a formatted table.
- Includes reservation ID, name, room, contact, and timestamp.
- Get Room Number
- Input reservation ID and guest name.
- Retrieves the room number if the reservation exists.
- Update Reservation
- Update guest name, room number, or contact info by providing reservation ID.
- Delete Reservation
- Deletes a reservation based on the ID after verifying its existence.
- Exit
- Exits the application gracefully with a loading animation.
javac HotelReservationSystem.java
java HotelReservationSystem
- Open the project folder.
- Make sure JDBC driver is added as a library.
- Run
HotelReservationSystem.java
.
- Refactor code to use
PreparedStatement
instead ofStatement
. - Avoid storing credentials in the source code. Use:
- Environment variables.
.properties
config file.
- Validate all user input.