Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

ONLINE MOVIE TICKET BOOKING SYSTEM

THIAGARAJAR COLLEGE OF ENGINEERING, MADURAI


625 015. Department of Computer Science and
Engineering

22CS470 – Databases Lab – Database Application

ONLINE MOVIE TICKET BOOKING SYSTEM


NAME REG_NO
DEVANTH V 22C147
DINESH KUMAR P 22C150
ALWINYABESH A 22C144

1 Introduction
The main purpose of our online ticket booking system is to revolutionize the way
customers purchase cinema tickets by offering a seamless, convenient, and automated
experience. Our system serves as an alternate avenue for patrons to secure their tickets,
bypassing the traditional hassle of queuing at the box office. Once the customer's data is inputted
into our robust database, our dedicated staff can rest assured that the entire process is hands-
free from thereon. Orders are efficiently received through the system and seamlessly processed
without any manual intervention required. This automation not only enhances the efficiency of
our operations but also ensures a swift and hassle-free booking experience for our valued
customers, thereby elevating their overall satisfaction with our service.

2 Application Users
In an online movie ticket booking system for cinema, the application users encompass a
diverse range of individuals, each playing a crucial role in the seamless functioning of the
platform. Firstly, there are the customers, or end-users, who utilize the system to browse
available movie listings, select preferred showtimes, and purchase tickets from the comfort of
their homes or on the go. These users seek convenience, reliability, and ease of use, expecting
a hassle-free experience from start to finish. Then, there are the administrators or staff members
responsible for managing the system behind the scenes. These individuals oversee various
aspects such as updating movie schedules, monitoring ticket sales, and resolving any technical
issues that may arise. Their primary goal is to ensure the smooth operation of the platform and
provide timely support to customers whenever needed

1
ONLINE MOVIE TICKET BOOKING SYSTEM

3 Functions Overview
The following functionality will be supported by the online movie ticket booking
system.
1. User Registration and Login.
2. Movie Listings.
3. Showtimes & Seat Selection.
4. Booking and Payment.

4 Detailed Functional Requirements

4.1 User Registration and Login:

● Users should be able to register with the system using their email or social media accounts
and login securely.

4.2 Movie Listings:

● The system should display a list of movies currently playing or upcoming, along with details
such as title, synopsis, genre, duration, and ratings.

4.3 Showtimes & Seat Selection:

● Users should be able to view showtimes for each movie, including dates, times, and
available theatres.
● Users should be able to select seats for the desired showtime from an interactive seating
map.

4.4 Booking and Payment:

● Once seats are selected, users should be able to proceed to booking and make payments
securely using various payment methods (credit/debit cards, mobile wallets, etc.).

5 Entities and Relationships

5.1 Entities and Relationships


Entities:
i. User
ii. Movie
iii. ShowTime
iv. Booking
Relationships:
i. User has a many-to-many relationship with Booking, as a user can make
multiple bookings, and each booking is made by one user.

2
ONLINE MOVIE TICKET BOOKING SYSTEM

ii. Showtime has a one-to-many relationship with Booking, as a showtime can


have multiple bookings, but each booking is for one showtime.
iii. Booking has a one-to-one relationship with Payment, as each booking
corresponds to one payment transaction
iv. Theater has a one-to-many relationship with Seat, as a theater can have multiple
seats, but each seat is in one theater.

6 Entity Relationship Diagram

Fig.1 ER-Diagram for online movie ticket booking system

3
ONLINE MOVIE TICKET BOOKING SYSTEM

7.Schema Diagram

Fig.3 Schema Diagram for online movie ticket booking system


7.1 ER to Relational Model:
Login:
Usersname (Username of the user)
password (Password of the user)
mail_id (Email ID of the user)
Explanation:
Login entity is likely associated with other entities to identify who made the booking
and payment transactions. It may have a one-to-many relationship with both
Booking_Transaction and Payment_Transaction, as a user can make multiple
bookings and payments.

Movie_Info:
Screen_No (Unique identifier for each screen in the cinema)
Show_Time (Time at which the movie is scheduled to be shown)
Curr_Movie (Current movie being shown)
Upcoming_Movie (Movie scheduled for future screenings)
Explanation:
Movie_Info holds information about movies, their showtimes, and the type of seats
available. It may not have direct relationships with the other entities unless it's

4
ONLINE MOVIE TICKET BOOKING SYSTEM

indirectly linked through bookings.

Booking_Transaction:
Ticket_No (Unique identifier for each booking transaction)
Movie_Name (Name of the movie booked)
Show_Time (Time of the show for the booked movie)
Movie_Date (Date of the booked movie)
Screen_No (The screen where the movie is booked)
Explanation:
Booking_Transaction records individual bookings made by users. It has a many-to-
one relationship with both Login and Movie_Info, as multiple bookings can be made
by one user for different movies and showtimes.

Payment_Transaction:
Ticket_No (Unique identifier for each payment transaction, possibly the same as in
Booking_Transaction)
Movie_Date (Date of the movie for which payment is made)
Acc_No (Account number used for payment)
Bank_Name (Name of the bank used for payment)
Explanation:
Payment_Transaction records individual payments made for bookings. It has a
many-to-one relationship with both Login and Booking_Transaction, as one user can
make multiple payments for different bookings

8.Functional Dependencies and Normalization


8.1 Schema.

Users (name, password, mail_id)

movie_info(screen_no,show_time ,curr_movie,upcoming_movie,type_seat)

booking_transaction(ticket_no ,movie_name,show_time,movie_date,screen_no)

payment_transaction(ticket_nomovie_dateacc_nobank_name)

8.2 Functional Dependencies.


S.No Relation Set of FD BCNF Checking
Name

1. Users Name The functional dependency name →


password password, age, mail_id, dob,
mail id
phone_no, match_name indicates
that {name} is a superkey.
Therefore, Users is in BCNF.

5
ONLINE MOVIE TICKET BOOKING SYSTEM

2. Movie_Info Screen_No, Screen_No → Curr_Movie,


Show_Time → Upcoming_Movie, Type_Seat:
Curr_Movie, Screen_No uniquely determines the
Upcoming_Movie, current movie, upcoming movie,
Type_Seat and type of seat. No partial
dependencies exist here.

3. Booking_ Ticket_No → Ticket_No → Movie_Name,


Transaction Movie_Name, Show_Time, Show_Time, Movie_Date, Screen_No:
Movie_Date, Screen_No Ticket_No uniquely determines all other
attributes. No partial dependencies exist
here.
Ticket_No is the candidate key as it
uniquely determines all attributes.

4. Payment_ Ticket_No → Movie_Date, Ticket_No → Movie_Date, Acc_No,


Transaction Acc_No, Bank_Name Bank_Name: Ticket_No uniquely
determines the movie date, account
number, and bank name. No partial
dependencies exist here.
Ticket_No is the candidate key as it
uniquely determines all attributes.

9. Data Dictionary
9.1 Users

Attribute Data Type Constraints Remarks

User name VARCHAR Unique, Not Username of the user


Null

Password VARCHAR Not Null Password of the user

Email_ID VARCHAR Unique, Not Email address of the user


Null

6
ONLINE MOVIE TICKET BOOKING SYSTEM

9.2 Movie_Info

Attribute Data Type Constraints Remarks

Screen_No INT Unique, Not Identification of the screen


Null

Show_Time DATETIME Not Null Timing of the movie


screening

Curr_Movie VARCHAR Not Null Currently screening


movie

Upcoming_ VARCHAR Not Null Upcoming movie to be


Movie screened

Type_Seat VARCHAR Not Null Type of seating


arrangement

9.3 Booking_Transaction

Attribute Data Type Constraints Remarks

Ticket_No INT Unique, Not Unique identifier for


Null booking
Movie_Name VARCHAR Not Null Name of the movie

Show_Time DATETIM Not Null Timing of the movie


E screening

9.4 Payment

Attribute Data Type Constraints Remarks

Ticket_No INT Unique, Not Unique identifier for


Null payment

Movie_Date DATE Not Null Date of the movie


screening

Acc_No VARCHAR Not Null Account number for


payment

7
ONLINE MOVIE TICKET BOOKING SYSTEM

10. Complete Database for Online Movie Ticket Booking System

8
ONLINE MOVIE TICKET BOOKING SYSTEM

9
ONLINE MOVIE TICKET BOOKING SYSTEM

10
ONLINE MOVIE TICKET BOOKING SYSTEM

11. Data Manipulation – SQL queries


11.1 Using simple SELECT statement (FROM clause) alone.
1) Selecting all columns from the movies table:
SELECT *
FROM movies;

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | movie_name | genre | release_date |


director | duration
---------|----------------|----------|--------------|----------
-----|----------
1 | Inception | Action | 2010-07-16 |
Christopher Nolan | 148
2 | The Shawshank Redemption | Drama |
1994-09-23 | Frank Darabont | 142
3 | Forrest Gump | Drama | 1994-07-06 |
Robert Zemeckis | 142

11
ONLINE MOVIE TICKET BOOKING SYSTEM

2)Selecting only the movie_name column from the movies table:


SELECT movie_name
FROM movies;

|---------|----------|-----|-------------------|-----------|------------|------------|
movie_name
--------------
Inception
The Shawshank Redemption
Forrest Gump

3)Selecting the customer_id column from the ticket_bookings


table:
SELECT customer_id
FROM ticket_bookings;

|---------|----------|-----|-------------------|-----------|------------|------------|
customer_id
-----------
101
102
103
104

11.2 Using WHERE clause in the SELECT statement.

1)Selecting movies directed by Christopher Nolan:


SELECT movie_id, movie_name
FROM movies
WHERE director = 'Christopher Nolan';

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | movie_name
---------|------------------
1 | Inception
4 | Interstellar

2)Selecting ticket bookings made by a specific customer:


SELECT *
FROM ticket_bookings
WHERE customer_id = 'ABC123';

|---------|----------|-----|-------------------|-----------|------------|------------|

booking_id | customer_id | movie_id | ticket_price | booking_date


-----------|-------------|----------|--------------|---------------------
1 | ABC123 |1 | 10.50 | 2023-05-10 15:30:00
3 | ABC123 |3 | 12.00 | 2023-05-12 18:45:00

12
ONLINE MOVIE TICKET BOOKING SYSTEM

3)Selecting movies released after 2020:


SELECT *
FROM movies
WHERE release_date > '2020-01-01';

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | movie_name | genre | release_date | director


| duration
---------|-------------------|----------|--------------|-------------------|--
--------
1 | Inception | Action | 2021-08-05 | Christopher
Nolan | 148
4 | Interstellar | Sci-Fi | 2022-03-10 | Christopher
Nolan | 169
5 | Tenet | Action | 2021-09-03 | Christopher
Nolan | 150

11.3 Using GROUP BY clause in the SELECT statement.

1)Total number of tickets sold for each movie:


SELECT movie_id, COUNT(*) AS total_tickets_sold
FROM ticket_bookings
GROUP BY movie_id;

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | total_tickets_sold
---------|--------------------
1 | 150
2 | 200
3 | 180

2)Number of tickets sold for each movie genre:


SELECT genre, COUNT(*) AS total_tickets_sold
FROM movies
INNER JOIN ticket_bookings ON movies.movie_id =
ticket_bookings.movie_id
GROUP BY genre;

|---------|----------|-----|-------------------|-----------|------------|------------|

genre | total_tickets_sold
---------|--------------------

13
ONLINE MOVIE TICKET BOOKING SYSTEM

Action | 300
Comedy | 250
Drama | 180

3)Average ticket price for each movie:


SELECT movie_id, AVG(ticket_price) AS average_ticket_price
FROM ticket_bookings
GROUP BY movie_id;

|---------|----------|-----|-------------------|-----------|------------|------------|
movie_id | average_ticket_price
---------|----------------------
1 | 10.50
2 | 9.75
3 | 11.25

11.4 Using the HAVING clause in the SELECT statement.

1)Movies with more than 100 tickets sold:


SELECT movie_id, COUNT(*) AS total_tickets_sold
FROM ticket_bookings
GROUP BY movie_id
HAVING total_tickets_sold > 100;

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | total_tickets_sold
---------|--------------------
1 | 150
2 | 200
3 | 180

2)Directors with more than 3 movies released:


SELECT director, COUNT(*) AS total_movies
FROM movies
GROUP BY director
HAVING total_movies > 3;

|---------|----------|-----|-------------------|-----------|------------|------------|

director | total_movies
-------------------|--------------
Christopher Nolan | 4
Steven Spielberg | 5

3)Customers with more than 5 bookings:


SELECT customer_id, COUNT(*) AS total_bookings
FROM ticket_bookings
GROUP BY customer_id

14
ONLINE MOVIE TICKET BOOKING SYSTEM

HAVING total_bookings > 5;

|---------|----------|-----|-------------------|-----------|------------|------------|

customer_id | total_bookings
-------------|----------------
ABC123 |8
XYZ789 |6

11.5 Using ORDER BY Clause in the SELECT statement.

1)Top 10 movies with the highest ticket sales:


SELECT movie_id, COUNT(*) AS total_tickets_sold
FROM ticket_bookings
GROUP BY movie_id
ORDER BY total_tickets_sold DESC
LIMIT 10;

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | total_tickets_sold
---------|--------------------
2 | 200
1 | 150
3 | 130
4 | 120
5 | 100

2)Movies ordered by release date:


SELECT movie_id, movie_name, release_date
FROM movies
ORDER BY release_date;

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | movie_name | release_date


---------|-----------------------|--------------
5 | Tenet | 2021-09-03
1 | Inception | 2021-08-05
4 | Interstellar | 2022-03-10
3 | Forrest Gump | 2023-02-15
2 | The Shawshank Redemption | 2023-05-01

3)Customers ordered by the total amount spent on tickets:


SELECT customer_id, SUM(ticket_price) AS
total_amount_spent
FROM ticket_bookings
GROUP BY customer_id
ORDER BY total_amount_spent DESC;

|---------|----------|-----|-------------------|-----------|------------|------------|

15
ONLINE MOVIE TICKET BOOKING SYSTEM

customer_id | total_amount_spent
-------------|-------------------
ABC123 | 120.50
XYZ789 | 95.75
DEF456 | 87.25

11.6 Using sub query.

1)Selecting movie names and release dates for movies booked by


customer '123':
SELECT movie_name, release_date
FROM movies
WHERE movie_id IN (SELECT movie_id
FROM ticket_bookings
WHERE customer_id = '123');
|---------|----------|-----|-------------------|-----------|------------|------------|

movie_name | release_date
-----------------------|--------------
Inception | 2021-08-05
The Shawshank Redemption | 2023-05-01

2)Selecting directors of movies booked by customer '456':


SELECT director
FROM movies
WHERE movie_id IN (SELECT movie_id
FROM tickets
WHERE ticket_id IN (SELECT ticket_id
FROM ticket_bookings
WHERE customer_id = '456'));

|---------|----------|-----|-------------------|-----------|------------|------------|

director
-------------
Christopher Nolan
Frank Darabont

3)Selecting movie genres of movies with high ticket sales:

SELECT genre
FROM movies
WHERE movie_id IN (SELECT movie_id
FROM ticket_bookings
GROUP BY movie_id
HAVING COUNT(*) > 100);

|---------|----------|-----|-------------------|-----------|------------|------------|

16
ONLINE MOVIE TICKET BOOKING SYSTEM

genre
------
Action
Drama

11.7 Using Nested query

1)Selecting movies directed by directors who have also directed


movies booked by customer '456':
SELECT movie_name, director
FROM movies
WHERE director IN (SELECT director
FROM movies
WHERE movie_id IN (SELECT movie_id
FROM tickets
WHERE ticket_id IN (SELECT ticket_id
FROM ticket_bookings
WHERE customer_id = '456')));

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_name | director
-----------------------|-------------
Inception | Christopher Nolan
The Shawshank Redemption | Frank Darabont

2)Selecting customers who have booked tickets for movies


directed by Christopher Nolan:
SELECT customer_id
FROM ticket_bookings
WHERE movie_id IN (SELECT movie_id
FROM movies
WHERE director = 'Christopher Nolan');

|---------|----------|-----|-------------------|-----------|------------|------------|

customer_id
-------------
ABC123
XYZ789

3)Selecting movies with genres that match genres of movies booked


by a specific customer:
SELECT movie_name, genre
FROM movies
WHERE genre IN (SELECT DISTINCT genre
FROM movies
WHERE movie_id IN (SELECT movie_id
FROM ticket_bookings

17
ONLINE MOVIE TICKET BOOKING SYSTEM

WHERE customer_id = '789'));

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_name | genre
-----------------------|----------
Inception | Action
Forrest Gump | Drama

11.8 Using DATE functions.


1)Selecting movies released after January 1, 2022:
SELECT *
FROM movies
WHERE release_date > '2022-01-01';

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | movie_name | genre | release_date


---------|-----------------------|----------|--------------
4 | Interstellar | Sci-Fi | 2022-03-10
5 | Tenet | Action | 2022-09-03
6 | Matrix Resurrections | Sci-Fi | 2022-12-22

2)Selecting movies released in the year 2023:


SELECT *
FROM movies
WHERE YEAR(release_date) = 2023;

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | movie_name | genre | release_date


---------|-----------------------|----------|--------------
1 | Inception | Action | 2023-08-05
3 | Forrest Gump | Drama | 2023-02-15
7 | Avatar: The Way of Water | Adventure | 2023-12-22

3)Selecting movies released in the last 30 days:


SELECT *
FROM movies
WHERE release_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY);

|---------|----------|-----|-------------------|-----------|------------|------------|

movie_id | movie_name | genre | release_date


---------|-----------------------|----------|--------------
6 | Matrix Resurrections | Sci-Fi | 2024-04-01
8 | Spider-Man: No Way Home | Action | 2024-03-23

18
ONLINE MOVIE TICKET BOOKING SYSTEM

12. Database Objects


12.1 Views:

12.2 Sequence:

19
ONLINE MOVIE TICKET BOOKING SYSTEM

12.3 Synonym:

20
ONLINE MOVIE TICKET BOOKING SYSTEM

12.4 Index:

21
ONLINE MOVIE TICKET BOOKING SYSTEM

13. PL/SQL Sub Programs


13.1 Procedures with cursors:

Example 1:

Procedure to Retrieve Available Seats for a Movie Show:

CREATE PROCEDURE GetAvailableSeatsForShow(IN show_id INT)


BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE seat_id INT;
DECLARE seat_cursor CURSOR FOR
SELECT seat_id FROM seats WHERE show_id = show_id AND booked = FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN seat_cursor;
seat_loop: LOOP
FETCH seat_cursor INTO seat_id;
IF done THEN
LEAVE seat_loop;
END IF;
-- Process seat_id here (e.g., display or store the available seat)
END LOOP;
CLOSE seat_cursor;
END;

Example 2:

Procedure to Retrieve User Bookings:

CREATE PROCEDURE GetUserBookings(IN user_id INT)


BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE booking_id INT;
DECLARE booking_date DATE;
DECLARE show_id INT;
DECLARE user_booking_cursor CURSOR FOR
SELECT booking_id, booking_date, show_id FROM bookings WHERE user_id = user_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN user_booking_cursor;
user_booking_loop: LOOP
FETCH user_booking_cursor INTO booking_id, booking_date, show_id;
IF done THEN
LEAVE user_booking_loop;
END IF;
-- Process the user bookings here (e.g., display or store them)
END LOOP;
CLOSE user_booking_cursor;
END;

22
ONLINE MOVIE TICKET BOOKING SYSTEM

13.2 Functions with cursors:

Example 1:
Function to Check Seat Availability for a Movie Show:
CREATE FUNCTION CheckSeatAvailability(show_id INT, seat_id INT) RETURNS
BOOLEAN
BEGIN
DECLARE is_available BOOLEAN;
SELECT booked INTO is_available FROM seats WHERE show_id = show_id AND seat_id
= seat_id;
RETURN NOT is_available;
END;
Example 2:

Function to Retrieve User's Booking History:

CREATE FUNCTION GetUserBookingHistory(user_id INT) RETURNS TABLE (


booking_id INT,
movie_title VARCHAR(255),
show_date DATE,
show_time TIME,
booking_date DATE,
seat_number INT
)
BEGIN
RETURN (
SELECT b.booking_id, m.movie_title, s.show_date, s.show_time, b.booking_date,
s.seat_number
FROM bookings b
INNER JOIN movie_shows s ON b.show_id = s.show_id
INNER JOIN movies m ON s.movie_id = m.movie_id
WHERE b.user_id = user_id
);
END;
13.3 Packages:
Example 1:

Package to Manage Booking Operations:

CREATE PACKAGE BookingPackage AS


PROCEDURE BookTicket(user_id INT, show_id INT, seat_id INT);
PROCEDURE CancelBooking(booking_id INT);
END BookingPackage;
/

CREATE PACKAGE BODY BookingPackage AS


PROCEDURE BookTicket(user_id INT, show_id INT, seat_id INT) AS

23
ONLINE MOVIE TICKET BOOKING SYSTEM

BEGIN
-- Implementation to book a ticket
END BookTicket;

PROCEDURE CancelBooking(booking_id INT) AS


BEGIN
-- Implementation to cancel a booking
END CancelBooking;
END BookingPackage;
/

Example 2:

Package to Retrieve Movie Information:

CREATE PACKAGE MoviePackage AS


FUNCTION GetMovieDetails(movie_id INT) RETURNS VARCHAR(255);
FUNCTION GetMovieGenre(movie_id INT) RETURNS VARCHAR(50);
END MoviePackage;
/

CREATE PACKAGE BODY MoviePackage AS


FUNCTION GetMovieDetails(movie_id INT) RETURNS VARCHAR(255) AS
BEGIN
DECLARE movie_details VARCHAR(255);
-- Implementation to retrieve movie details
RETURN movie_details;
END GetMovieDetails;

FUNCTION GetMovieGenre(movie_id INT) RETURNS VARCHAR(50) AS


BEGIN
DECLARE movie_genre VARCHAR(50);
-- Implementation to retrieve movie genre
RETURN movie_genre;
END GetMovieGenre;
END MoviePackage;
/
13.4 Triggers:
Example 1:

Trigger to Update Available Seats After Booking:

24
ONLINE MOVIE TICKET BOOKING SYSTEM

CREATE TRIGGER UpdateAvailableSeats AFTER INSERT ON bookings


FOR EACH ROW
BEGIN
DECLARE total_booked INT;
SELECT COUNT(*) INTO total_booked FROM bookings WHERE show_id =
NEW.show_id;
UPDATE movie_shows SET available_seats = total_seats - total_booked WHERE show_id
= NEW.show_id;
END;
Example 2:

Trigger to Update Booking Count for Users:

CREATE TRIGGER UpdateBookingCount AFTER INSERT ON bookings


FOR EACH ROW
BEGIN
UPDATE users SET booking_count = booking_count + 1 WHERE user_id = NEW.user_id;
END;

14. Application Design using Higer Level Language


14.1 JDBC:
JDBC (Java Database Connectivity) is a Java API that allows Java programs to
interact with databases. It provides methods to query and update data in a database, and it is
widely used for database connectivity in Java applications.

Below is the implementation of my application ( Online Movie


Ticket Booking System Using JDBC):
import java.sql.*;
import java.util.Scanner;

public class DMLExample {


public static void main(String[] args) {
try {
// Load the JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");

// Connection details
String URL = "jdbc:oracle:thin:@localhost:1521:xe"; //
JDBC URL for the Oracle database
String username = "system"; // Username for connecting to
the database
String password = "yoga"; // Password for connecting to the
database

25
ONLINE MOVIE TICKET BOOKING SYSTEM

// Establish the connection


Connection con = DriverManager.getConnection(URL,
username, password);
System.out.println("Connected to the database.");

// Scanner object for user input


Scanner scanner = new Scanner(System.in);

// Prompt user for choice


System.out.println("Enter your choice (1: Insert, 2: Update, 3:
Delete): ");
int choice = scanner.nextInt();

switch (choice) {
case 1: // Insert
System.out.println("Enter movie_id: ");
int movieId = scanner.nextInt();
System.out.println("Enter movie_name: ");
String movieName = scanner.next();
System.out.println("Enter release_date (yyyy-mm-dd):
");
String releaseDateStr = scanner.next();
Date releaseDate = Date.valueOf(releaseDateStr);

// Inserting records into the movies table


try (PreparedStatement insertMovieStmt =
con.prepareStatement("INSERT INTO movies VALUES (?, ?, ?)"))
{
insertMovieStmt.setInt(1, movieId);
insertMovieStmt.setString(2, movieName);
insertMovieStmt.setDate(3, releaseDate);
int movieInsertResult =
insertMovieStmt.executeUpdate();
System.out.println(movieInsertResult + " record(s)
inserted into movies table.");
}
break;

case 2: // Update
System.out.println("Enter movie_id: ");
int updateMovieId = scanner.nextInt();
System.out.println("Enter new movie_name: ");
String newMovieName = scanner.next();

// Updating records in the movies table


try (PreparedStatement updateMovieStmt =
con.prepareStatement("UPDATE movies SET movie_name = ?
WHERE movie_id = ?")) {
updateMovieStmt.setString(1, newMovieName); //
New movie name
updateMovieStmt.setInt(2, updateMovieId); // Movie
ID

26
ONLINE MOVIE TICKET BOOKING SYSTEM

int movieUpdateResult =
updateMovieStmt.executeUpdate();
System.out.println(movieUpdateResult + " record(s)
updated in movies table.");
}
break;

case 3: // Delete
System.out.println("Enter movie_id to delete: ");
int deleteMovieId = scanner.nextInt();

// Deleting records from the movies table


try (PreparedStatement deleteMovieStmt =
con.prepareStatement("DELETE FROM movies WHERE movie_id
= ?")) {
deleteMovieStmt.setInt(1, deleteMovieId); // Movie
ID
int movieDeleteResult =
deleteMovieStmt.executeUpdate();
System.out.println(movieDeleteResult + " record(s)
deleted from movies table.");
}
break;

default:
System.out.println("Invalid choice!");
}

// Closing resources
con.close();
scanner.close();
System.out.println("Disconnected from the database.");

} catch (Exception e) {
e.printStackTrace();
}
}
}

15. Results/ Demo for the Application


So, First we login to the system with username and password that we already data has been fed
into the database. Then it takes into another page where we select movie and then after we
selecting movie another page comes then we select show timings. After selecting show timings
it takes into another page there we select number of tickets we want. After selecting number of
tickets it takes into another page there we print ticket with cost.

27
ONLINE MOVIE TICKET BOOKING SYSTEM

28
ONLINE MOVIE TICKET BOOKING SYSTEM

29
ONLINE MOVIE TICKET BOOKING SYSTEM

30
ONLINE MOVIE TICKET BOOKING SYSTEM

31
ONLINE MOVIE TICKET BOOKING SYSTEM

32
ONLINE MOVIE TICKET BOOKING SYSTEM

33
ONLINE MOVIE TICKET BOOKING SYSTEM

34

You might also like