This project implements a console-based Train Reservation System using Java and MySQL. The system enables users to register, log in, book train tickets, check PNR status, and cancel booked tickets. It also maintains waiting lists, processes UPI-based mock payments, and handles automatic promotion of passengers from the waiting list upon cancellation.
The Train Reservation System is designed to simulate the core functionalities of a railway ticket booking system. It demonstrates:
- database connectivity using JDBC
- transaction handling
- input validation
- exception management
- waiting list and PNR management mechanisms
The application operates entirely through a command-line interface.
- New user registration
- User login authentication
- Search trains by source and destination
- Automatic PNR generation
- Booking based on seat availability
- Partial booking with waiting list assignment
- Passenger-level status handling
- UPI-based simulated payment validation
- Balance verification before booking
- Refund processing during cancellation
- Current booking status
- Waiting list position (if applicable)
- Passenger details retrieval
- Refund computation and processing
- Release of seats upon cancellation
- Automatic movement of waiting list passengers to confirmed status
| Component | Details |
|---|---|
| Programming Language | Java |
| Database | MySQL |
| Database Connectivity | JDBC |
| Execution Environment | Console Application |
The system requires the following tables:
- user
- train
- pnr
- passenger
- upi
- wait
Each table should be designed with appropriate primary and foreign keys to ensure data integrity.
- Java JDK 8 or later
- MySQL Server
- MySQL JDBC Driver
CREATE DATABASE project;
USE project;Modify in the main method:
String url = "jdbc:mysql://localhost:3306/project";
String user = "root";
String password = "your_mysql_password";javac TrainReservationSystem.javajava TrainReservationSystem-
User signs up or logs in
-
User selects one of the operations:
- Book Ticket
- Cancel Ticket
- Check PNR Status
- Logout
-
System interacts with MySQL database using JDBC
-
Transactions are used to maintain data consistency
-
Waiting list and seat availability are automatically updated
-
Password must contain at least four characters
-
Phone number must be exactly ten digits
-
Accepted email formats include:
@gmail.com@yahoo.com.in.ac.in
-
One PNR is generated per booking
-
Waiting list positions are allocated in sequential order