JDBC Practice Questions
JDBC Practice Questions
1. Add new project details as more freelancers and clients are onboarded.
2. Update the payment status when a project hits a milestone or gets completed.
4. Retrieve all project details for tracking the project's status and maintaining client
relationships.
Jake has been tasked to create a Java application using JDBC and MySQL to implement
this system. The application must support CRUD (Create, Read, Update, Delete)
operations and handle SQLExceptions efficiently to ensure robust performance.
Table Structure:
• payment: INT
Additional Requirements:
Input Format:
Insert Operation:
Input consists of an operation number (1), followed by the attributes for a new project:
• projectId (INT)
• clientName (VARCHAR)
• projectTitle (VARCHAR)
• projectStatus (VARCHAR)
• payment (INT)
Update Operation:
• projectId (INT)
• newPayment (INT)
Delete Operation:
• projectId (INT)
Output Format:
Insert Operation:
Outputs the message "Project added successfully." followed by the list of all projects
sorted by payment in descending order.
Update Operation:
Outputs the message "Payment updated successfully." followed by the list of all
projects sorted by payment in descending order.
Delete Operation:
Outputs the message "Project deleted successfully." followed by the list of all projects
sorted by payment in descending order.
Sample 1 Input:
2006
Sarah Johnson
Website Design
Ongoing
2500
Sample 1 Output:
Project ID: 2006, Client: Sarah Johnson, Project: Website Design, Status: Ongoing,
Payment: 2500
Project ID: 2002, Client: Mike Lee, Project: Mobile App, Status: Finished, Payment: 1800
Project ID: 2005, Client: Kate Reed, Project: Marketing Campaign, Status: Finished,
Payment: 1300
Project ID: 2004, Client: Alex Kim, Project: Social Media Strategy, Status: Ongoing,
Payment: 900
Project ID: 2001, Client: Emily White, Project: Logo Design, Status: Ongoing, Payment:
600
Project ID: 2003, Client: Tom Green, Project: SEO Plan, Status: Pending, Payment: 400
Sample 2 Input:
2001
800
Sample 2 Output:
Project ID: 2002, Client: Mike Lee, Project: Mobile App, Status: Finished, Payment: 1800
Project ID: 2005, Client: Kate Reed, Project: Marketing Campaign, Status: Finished,
Payment: 1300
Project ID: 2001, Client: Emily White, Project: Logo Design, Status: Ongoing, Payment:
800
Project ID: 2004, Client: Alex Kim, Project: Social Media Strategy, Status: Ongoing,
Payment: 900
Project ID: 2003, Client: Tom Green, Project: SEO Plan, Status: Pending, Payment: 400
Sample 3 Input:
2001
Sample 3 Output:
Project ID: 2002, Client: Mike Lee, Project: Mobile App, Status: Finished, Payment: 1800
Project ID: 2005, Client: Kate Reed, Project: Marketing Campaign, Status: Finished,
Payment: 1300
Project ID: 2004, Client: Alex Kim, Project: Social Media Strategy, Status: Ongoing,
Payment: 900
Project ID: 2003, Client: Tom Green, Project: SEO Plan, Status: Pending, Payment: 400
Sample 4 Input:
Sample 4 Output:
Project ID: 2002, Client: Mike Lee, Project: Mobile App, Status: Finished, Payment: 1800
Project ID: 2005, Client: Kate Reed, Project: Marketing Campaign, Status: Finished,
Payment: 1300
Project ID: 2004, Client: Alex Kim, Project: Social Media Strategy, Status: Ongoing,
Payment: 900
Project ID: 2001, Client: Emily White, Project: Logo Design, Status: Ongoing, Payment:
600
Project ID: 2003, Client: Tom Green, Project: SEO Plan, Status: Pending, Payment: 400
QUESTION 2:
You are tasked with developing a Java application to manage workshops at a Lifelong
Learning Center. The application will track workshop details, instructors, participants,
and their progress status using JDBC and MySQL. The system must support CRUD
(Create, Read, Update, Delete) operations and display the workshops properly.
• workshopTitle: VARCHAR(100)
• leadInstructor: VARCHAR(100)
• numParticipants: INT
Operations:
NOTES:
• The workshopId range for the existing records is between 3001 and 3005.
Input Format:
The input consists of an operation number, followed by the required details for each
operation:
Output Format:
1. Insert Operation: Display "Workshop successfully added." followed by the
updated list of workshops in ascending order by workshopId.
Sample Input/Output 1:
Input:
3006
Creative Writing
Sophia Hill
15
In Progress
Output:
Workshop ID: 3001, Title: Technology for Seniors, Instructor: Lisa Brown, Participants:
20, Status: Completed
Workshop ID: 3002, Title: Wellness & Fitness, Instructor: James Parker, Participants: 10,
Status: In Progress
Workshop ID: 3003, Title: Pottery Class, Instructor: Olivia White, Participants: 12,
Status: Planned
Workshop ID: 3004, Title: Photography Basics, Instructor: Emily Green, Participants: 18,
Status: Completed
Workshop ID: 3005, Title: Gardening 101, Instructor: Robert Clark, Participants: 8,
Status: Planned
Workshop ID: 3006, Title: Creative Writing, Instructor: Sophia Hill, Participants: 15,
Status: In Progress
Sample Input/Output 2:
Input:
3003
Anna Williams
16
Output:
Workshop ID: 3001, Title: Technology for Seniors, Instructor: Lisa Brown, Participants:
20, Status: Completed
Workshop ID: 3002, Title: Wellness & Fitness, Instructor: James Parker, Participants: 10,
Status: In Progress
Workshop ID: 3003, Title: Pottery Class, Instructor: Anna Williams, Participants: 16,
Status: Planned
Workshop ID: 3004, Title: Photography Basics, Instructor: Emily Green, Participants: 18,
Status: Completed
Workshop ID: 3005, Title: Gardening 101, Instructor: Robert Clark, Participants: 8,
Status: Planned
QUESTION 3
Alex is a software developer for a book subscription service called "Reader's Paradise."
The service offers subscription-based book deliveries, where customers receive their
favorite genre or specific book title every month. The management team needs a system
to track these subscriptions and manage key operations like delivery status, monthly
payments, and customer feedback in the form of ratings.
Alex is tasked with developing a Java application using JDBC and MySQL to manage the
book subscriptions and associated tasks.
Table Structure:
Operations:
o After inserting, the system will display all existing subscriptions sorted by
subscriptionId in ascending order.
o After updating, the system will display all existing subscriptions sorted by
subscriptionId in ascending order.
o The system will delete a subscription if the provided rating matches any
existing subscription.
o After deleting, the system will display all remaining subscriptions sorted
by subscriptionId in ascending order.
NOTE:
• The table name is case-sensitive and must match the one specified above.
• The table has already been created, and some rows have been inserted.
Input Format:
o subscriptionId (integer)
o bookTitle (string)
o monthlyPayment (integer)
o subscriptionId (integer)
o rating (integer between 1 and 5). The system will delete the first
subscription it finds with the given rating.
Display subscriptions:
• No input is required for this operation; it will simply display all subscriptions
sorted by subscriptionId in ascending order.
Output Format:
Insert Operation:
Update Operation:
Delete Operation:
Sample 1 Input:
1006
Pending
50
Sample 1 Output:
Subscription ID: 1001, Book Title: To Kill a Mockingbird, Delivery Status: Pending,
Monthly Payment: 30, Rating: 4
Subscription ID: 1002, Book Title: 1984, Delivery Status: Delivered, Monthly Payment:
35, Rating: 5
Subscription ID: 1003, Book Title: Moby Dick, Delivery Status: Cancelled, Monthly
Payment: 25, Rating: 3
Subscription ID: 1004, Book Title: Pride and Prejudice, Delivery Status: Pending,
Monthly Payment: 40, Rating: 4
Subscription ID: 1005, Book Title: War and Peace, Delivery Status: Delivered, Monthly
Payment: 50, Rating: 5
Subscription ID: 1006, Book Title: The Great Gatsby, Delivery Status: Pending, Monthly
Payment: 50, Rating: 5
Sample 2 Input:
1002
Cancelled
40
Sample 2 Output:
Subscription ID: 1001, Book Title: To Kill a Mockingbird, Delivery Status: Pending,
Monthly Payment: 30, Rating: 4
Subscription ID: 1002, Book Title: 1984, Delivery Status: Cancelled, Monthly Payment:
40, Rating: 5
Subscription ID: 1003, Book Title: Moby Dick, Delivery Status: Cancelled, Monthly
Payment: 25, Rating: 3
Subscription ID: 1004, Book Title: Pride and Prejudice, Delivery Status: Pending,
Monthly Payment: 40, Rating: 4
Subscription ID: 1005, Book Title: War and Peace, Delivery Status: Delivered, Monthly
Payment: 50, Rating: 5
Sample 3 Input:
Sample 3 Output:
Subscription ID: 1001, Book Title: To Kill a Mockingbird, Delivery Status: Pending,
Monthly Payment: 30, Rating: 4
Subscription ID: 1002, Book Title: 1984, Delivery Status: Cancelled, Monthly Payment:
40, Rating: 5
Subscription ID: 1004, Book Title: Pride and Prejudice, Delivery Status: Pending,
Monthly Payment: 40, Rating: 4
Subscription ID: 1005, Book Title: War and Peace, Delivery Status: Delivered, Monthly
Payment: 50, Rating: 5
Sample 4 Input:
Sample 4 Output:
Subscription ID: 1001, Book Title: To Kill a Mockingbird, Delivery Status: Pending,
Monthly Payment: 30, Rating: 4
Subscription ID: 1002, Book Title: 1984, Delivery Status: Cancelled, Monthly Payment:
40, Rating: 5
Subscription ID: 1003, Book Title: Moby Dick, Delivery Status: Cancelled, Monthly
Payment: 25, Rating: 3
Subscription ID: 1004, Book Title: Pride and Prejudice, Delivery Status: Pending,
Monthly Payment: 40, Rating: 4
Subscription ID: 1005, Book Title: War and Peace, Delivery Status: Delivered, Monthly
Payment: 50, Rating: 5
QUESTION 4:
In a bustling city, the public library plays a critical role in supporting the education and
leisure of its citizens. To ensure that the books are well-maintained, the library
management has implemented a system for tracking book maintenance tasks. This
system helps monitor tasks assigned to different maintenance staff, categorize them by
priority, and determine the frequency of each task. As the lead developer, your
responsibility is to create a Java application using JDBC and MySQL to manage these
maintenance tasks efficiently.
Table Structure:
Operations:
NOTE:
• The table name is case-sensitive and must match the one specified above.
• The table has already been created, and some records have been inserted.
Input Format:
taskId (integer)
bookTitle (string)
assignedStaff (string)
3
assignedStaff (string)
Output Format:
Sample 1 Input:
2006
Moby Dick
Staff B
High
Monthly
Sample 1 Output:
Task ID: 2001, Book Title: To Kill a Mockingbird, Assigned Staff: Staff A, Priority: High,
Interval: Weekly
Task ID: 2002, Book Title: 1984, Assigned Staff: Staff C, Priority: Medium, Interval:
Monthly
Task ID: 2003, Book Title: The Catcher in the Rye, Assigned Staff: Staff D, Priority: Low,
Interval: Quarterly
Task ID: 2004, Book Title: The Great Gatsby, Assigned Staff: Staff E, Priority: High,
Interval: Monthly
Task ID: 2005, Book Title: War and Peace, Assigned Staff: Staff F, Priority: Medium,
Interval: Weekly
Task ID: 2006, Book Title: Moby Dick, Assigned Staff: Staff B, Priority: High, Interval:
Monthly
Sample 2 Input:
2003
Medium
Weekly
Sample 2 Output:
Task ID: 2001, Book Title: To Kill a Mockingbird, Assigned Staff: Staff A, Priority: High,
Interval: Weekly
Task ID: 2002, Book Title: 1984, Assigned Staff: Staff C, Priority: Medium, Interval:
Monthly
Task ID: 2003, Book Title: The Catcher in the Rye, Assigned Staff: Staff D, Priority:
Medium, Interval: Weekly
Task ID: 2004, Book Title: The Great Gatsby, Assigned Staff: Staff E, Priority: High,
Interval: Monthly
Task ID: 2005, Book Title: War and Peace, Assigned Staff: Staff F, Priority: Medium,
Interval: Weekly
Sample 3 Input:
Staff A
Sample 3 Output:
Task ID: 2002, Book Title: 1984, Assigned Staff: Staff C, Priority: Medium, Interval:
Monthly
Task ID: 2003, Book Title: The Catcher in the Rye, Assigned Staff: Staff D, Priority:
Medium, Interval: Weekly
Task ID: 2004, Book Title: The Great Gatsby, Assigned Staff: Staff E, Priority: High,
Interval: Monthly
Task ID: 2005, Book Title: War and Peace, Assigned Staff: Staff F, Priority: Medium,
Interval: Weekly
Sample 4 Input:
Sample 4 Output:
Task ID: 2001, Book Title: To Kill a Mockingbird, Assigned Staff: Staff A, Priority: High,
Interval: Weekly
Task ID: 2002, Book Title: 1984, Assigned Staff: Staff C, Priority: Medium, Interval:
Monthly
Task ID: 2003, Book Title: The Catcher in the Rye, Assigned Staff: Staff D, Priority:
Medium, Interval: Weekly
Task ID: 2004, Book Title: The Great Gatsby, Assigned Staff: Staff E, Priority: High,
Interval: Monthly
Task ID: 2005, Book Title: War and Peace, Assigned Staff: Staff F, Priority: Medium,
Interval: Weekly
QUESTION 5:
Task Management System for Freelance Projects
Table Structure:
Operations:
The system will delete the first task found associated with the specified freelancer.
After deletion, the system will display all remaining tasks sorted by completionPercent
in ascending order.
NOTE:
• The table name is case-sensitive and must match the specified one.
• Assume the table has been created and contains some pre-existing records, with
taskId values ranging between 101 and 105.
Input Format:
taskId (integer)
projectName (string)
freelancer (string)
freelancer (string)
Output Format:
Task ID: ..., Project Name: ..., Freelancer: ..., Category: ..., Completion: ...%
Task ID: ..., Project Name: ..., Freelancer: ..., Category: ..., Completion: ...%
Task ID: ..., Project Name: ..., Freelancer: ..., Category: ..., Completion: ...%
Task ID: ..., Project Name: ..., Freelancer: ..., Category: ..., Completion: ...%
Sample 1 Input:
1
106
Jane
Design
45
Sample 1 Output:
Task ID: 102, Project Name: Website Redesign, Freelancer: Bob, Category:
Development, Completion: 30%
Task ID: 101, Project Name: Logo Creation, Freelancer: Alice, Category: Design,
Completion: 50%
Task ID: 106, Project Name: Mobile App Design, Freelancer: Jane, Category: Design,
Completion: 45%
Task ID: 105, Project Name: Social Media Strategy, Freelancer: David, Category:
Marketing, Completion: 75%
Sample 2 Input:
101
Development
60
Sample 2 Output:
Task ID: 102, Project Name: Website Redesign, Freelancer: Bob, Category:
Development, Completion: 30%
Task ID: 101, Project Name: Logo Creation, Freelancer: Alice, Category: Development,
Completion: 60%
Task ID: 105, Project Name: Social Media Strategy, Freelancer: David, Category:
Marketing, Completion: 75%
Sample 3 Input:
3
Alice
Sample 3 Output:
Task ID: 102, Project Name: Website Redesign, Freelancer: Bob, Category:
Development, Completion: 30%
Task ID: 105, Project Name: Social Media Strategy, Freelancer: David, Category:
Marketing, Completion: 75%
Sample 4 Input:
Sample 4 Output:
Task ID: 102, Project Name: Website Redesign, Freelancer: Bob, Category:
Development, Completion: 30%
Task ID: 105, Project Name: Social Media Strategy, Freelancer: David, Category:
Marketing, Completion: 75%
QUESTION 6:
Recipe Management System
Table Structure:
• prepCount: INT NOT NULL // Number of times the recipe has been prepared
Operations:
o After adding, the system will display all recipes sorted by prepCount in
descending order.
o After updating, the system will display all recipes sorted by prepCount in
descending order.
o The system will delete the first recipe associated with the specified
chefName.
o After deletion, the system will display all recipes sorted by prepCount in
descending order.
NOTE:
• The table name is case-sensitive and must match the one specified above.
• The table has been created, and some tuples have already been inserted with
IDs ranging from 1001 to 1005.
Input Format
recipeId (integer)
recipeTitle (string)
chefName (string)
chefName (string)
Output Format
The system will display: "Recipe added successfully." followed by a list of all recipes
sorted by prepCount in descending order.
The system will display: "Preparation count updated successfully." followed by a list of
all recipes sorted by prepCount in descending order.
If a recipe is deleted, the system will display: "Recipe deleted successfully." followed by
a list of all remaining recipes sorted by prepCount in descending order.
The system will display all recipes sorted by prepCount in descending order.
Sample 1 Input:
1006
Pancakes
Emily Johnson
Breakfast
450
Sample 1 Output:
ID: 1006, Title: Pancakes, Chef: Emily Johnson, Meal Type: Breakfast, Prepared: 450
times
ID: 1003, Title: Sushi Rolls, Chef: Akira Sato, Meal Type: Lunch, Prepared: 300 times
ID: 1001, Title: Spaghetti Bolognese, Chef: Mario Rossi, Meal Type: Dinner, Prepared:
250 times
ID: 1004, Title: Chocolate Mousse, Chef: Sophie Laine, Meal Type: Dessert, Prepared:
200 times
ID: 1005, Title: Caesar Salad, Chef: John Green, Meal Type: Lunch, Prepared: 150 times
ID: 1002, Title: French Toast, Chef: Sarah Lee, Meal Type: Breakfast, Prepared: 100 times
Sample 2 Input:
1001
300
Sample 2 Output:
ID: 1001, Title: Spaghetti Bolognese, Chef: Mario Rossi, Meal Type: Dinner, Prepared:
300 times
ID: 1003, Title: Sushi Rolls, Chef: Akira Sato, Meal Type: Lunch, Prepared: 300 times
ID: 1004, Title: Chocolate Mousse, Chef: Sophie Laine, Meal Type: Dessert, Prepared:
200 times
ID: 1005, Title: Caesar Salad, Chef: John Green, Meal Type: Lunch, Prepared: 150 times
ID: 1002, Title: French Toast, Chef: Sarah Lee, Meal Type: Breakfast, Prepared: 100 times
Sample 3 Input:
Mario Rossi
Sample 3 Output:
ID: 1004, Title: Chocolate Mousse, Chef: Sophie Laine, Meal Type: Dessert, Prepared:
200 times
ID: 1005, Title: Caesar Salad, Chef: John Green, Meal Type: Lunch, Prepared: 150 times
ID: 1002, Title: French Toast, Chef: Sarah Lee, Meal Type: Breakfast, Prepared: 100 times
Sample 4 Input:
Sample 4 Output:
ID: 1003, Title: Sushi Rolls, Chef: Akira Sato, Meal Type: Lunch, Prepared: 300 times
ID: 1001, Title: Spaghetti Bolognese, Chef: Mario Rossi, Meal Type: Dinner, Prepared:
250 times
ID: 1004, Title: Chocolate Mousse, Chef: Sophie Laine, Meal Type: Dessert, Prepared:
200 times
ID: 1005, Title: Caesar Salad, Chef: John Green, Meal Type: Lunch, Prepared: 150 times
ID: 1002, Title: French Toast, Chef: Sarah Lee, Meal Type: Breakfast, Prepared: 100 times
QUESTION 7:
Table Structure:
• maintenanceSchedule: INT NOT NULL — Number of trips the vehicle can make
before needing maintenance.
Operations:
The system will delete the first vehicle that has the specified batteryStatus percentage.
After deletion, the system will display all remaining vehicles sorted by batteryStatus in
descending order.
NOTE:
• The table name is case-sensitive and must match the one specified above.
• The table is created, and some records have already been inserted into the table.
Input Format:
vehicleId (integer)
vehicleModel (string)
passengerCapacity (integer)
batteryStatus (integer)
maintenanceSchedule (integer)
vehicleId (integer)
vehicleModel (string)
passengerCapacity (integer)
batteryStatus (integer)
maintenanceSchedule (integer)
Output Format:
• For Displaying All Vehicles: The system will display all vehicles sorted by
batteryStatus in descending order.
Sample 1 Input:
1006
Tesla Model X
85
12
Sample 1 Output:
ID: 1003, Model: Waymo One, Capacity: 5, Battery Status: 95%, Maintenance Schedule:
15
ID: 1006, Model: Tesla Model X, Capacity: 7, Battery Status: 85%, Maintenance
Schedule: 12
ID: 1001, Model: Cruise Origin, Capacity: 6, Battery Status: 80%, Maintenance
Schedule: 10
ID: 1002, Model: Zoox Shuttle, Capacity: 4, Battery Status: 60%, Maintenance Schedule:
8
ID: 1005, Model: Apollo RT6, Capacity: 10, Battery Status: 55%, Maintenance Schedule:
15
ID: 1004, Model: Nuro R2, Capacity: 2, Battery Status: 40%, Maintenance Schedule: 5
Sample 2 Input:
2
1003
Tesla Model Y
70
10
Sample 2 Output:
ID: 1001, Model: Cruise Origin, Capacity: 6, Battery Status: 80%, Maintenance
Schedule: 10
ID: 1003, Model: Tesla Model Y, Capacity: 6, Battery Status: 70%, Maintenance
Schedule: 10
ID: 1002, Model: Zoox Shuttle, Capacity: 4, Battery Status: 60%, Maintenance Schedule:
8
ID: 1005, Model: Apollo RT6, Capacity: 10, Battery Status: 55%, Maintenance Schedule:
15
ID: 1004, Model: Nuro R2, Capacity: 2, Battery Status: 40%, Maintenance Schedule: 5
Sample 3 Input:
95
Sample 3 Output:
ID: 1001, Model: Cruise Origin, Capacity: 6, Battery Status: 80%, Maintenance
Schedule: 10
ID: 1002, Model: Zoox Shuttle, Capacity: 4, Battery Status: 60%, Maintenance Schedule:
8
ID: 1005, Model: Apollo RT6, Capacity: 10, Battery Status: 55%, Maintenance Schedule:
15
ID: 1004, Model: Nuro R2, Capacity: 2, Battery Status: 40%, Maintenance Schedule: 5
Sample 4 Input:
4
Sample 4 Output:
ID: 1003, Model: Waymo One, Capacity: 5, Battery Status: 95%, Maintenance Schedule:
15
ID: 1001, Model: Cruise Origin, Capacity: 6, Battery Status: 80%, Maintenance
Schedule: 10
ID: 1002, Model: Zoox Shuttle, Capacity: 4, Battery Status: 60%, Maintenance Schedule:
8
ID: 1005, Model: Apollo RT6, Capacity: 10, Battery Status: 55%, Maintenance Schedule:
15
ID: 1004, Model: Nuro R2, Capacity: 2, Battery Status: 40%, Maintenance Schedule: 5
QUESTION 8:
Table Structure:
• conditionName: VARCHAR(50)
• symptoms: VARCHAR(100)
• treatment: VARCHAR(100)
Operations:
1. Insert Condition Details: Add a new health condition entry with all details
including conditionId, conditionName, severityLevel, symptoms, and treatment.
4. Show All Condition Details: Display all health condition records sorted by
severityLevel in descending order.
NOTE:
• The table name is case-sensitive and must match the one specified above.
• The table is created, and some entries have already been inserted into the table.
Input Format:
Output Format:
The output should perform the selected CRUD operation based on the input. For each
operation, display appropriate messages and show updated condition details as
follows:
Sample Input:
1008
Hypertension
7.5
Headaches, Dizziness
Sample Output:
ID: 1002, Name: Diabetes, Severity Level: 8.0, Symptoms: Increased thirst, Fatigue,
Treatment: Insulin, Lifestyle changes
ID: 1005, Name: Asthma, Severity Level: 6.0, Symptoms: Shortness of breath,
Coughing, Treatment: Inhalers, Avoiding triggers
ID: 1008, Name: Hypertension, Severity Level: 7.5, Symptoms: Headaches, Dizziness,
Treatment: Lifestyle changes, Medication
ID: 1001, Name: Influenza, Severity Level: 4.5, Symptoms: Fever, Cough, Treatment:
Rest, Hydration
ID: 1003, Name: Malaria, Severity Level: 5.0, Symptoms: Fever, Chills, Sweating,
Treatment: Antimalarial medications
ID: 1004, Name: Tuberculosis, Severity Level: 3.0, Symptoms: Cough, Weight Loss,
Treatment: Antibiotics