Skip to content

Ratankumar27/Hotel-Reservation-System-Java-JDBC-MySQL-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿจ Hotel Reservation System (Java + JDBC + MySQL)

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.

๐ŸŒŸ Features

  • 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.

๐Ÿงฐ Technologies Used

Technology Description
JavaProgramming language used
JDBCJava Database Connectivity API
MySQLRelational database for storing reservation data
IntelliJ / EclipseRecommended IDE for development

๐Ÿ—ƒ๏ธ Database Schema

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 );

๐Ÿ› ๏ธ Setup Instructions

  1. Clone this repository or download the source code.
  2. Set up MySQL database:
    • Run the SQL script above.
    • Make sure MySQL is running locally on port 3306.
  3. 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";
    
  1. 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).
  2. Compile and Run the Program:
    • From your IDE or using javac and java commands.

๐Ÿ“Œ Main Tasks / Functionalities

  1. Reserve a Room
    • Input guest name, room number, and contact number.
    • Saves the reservation to the database.
  2. View Reservations
    • Lists all reservations in a formatted table.
    • Includes reservation ID, name, room, contact, and timestamp.
  3. Get Room Number
    • Input reservation ID and guest name.
    • Retrieves the room number if the reservation exists.
  4. Update Reservation
    • Update guest name, room number, or contact info by providing reservation ID.
  5. Delete Reservation
    • Deletes a reservation based on the ID after verifying its existence.
  6. Exit
    • Exits the application gracefully with a loading animation.

โ–ถ๏ธ How to Run

Option 1: Using Terminal


javac HotelReservationSystem.java
java HotelReservationSystem
    

Option 2: Using IntelliJ or Eclipse

  • Open the project folder.
  • Make sure JDBC driver is added as a library.
  • Run HotelReservationSystem.java.

๐Ÿ” Security Notes

โš ๏ธ WARNING: The current implementation uses SQL string concatenation, which is vulnerable to SQL injection.

Recommendations:

  • Refactor code to use PreparedStatement instead of Statement.
  • Avoid storing credentials in the source code. Use:
    • Environment variables.
    • .properties config file.
  • Validate all user input.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages