This Java console application manages a restaurant's customers, employees, menu items, and orders. It connects to a MySQL database and demonstrates CRUD operations, transactions, views, and stored procedures.
Features include:
- Customer, Employee, and MenuItem CRUD operations (Create, Read, Update, Delete).
- Transaction demo: place orders with multiple items, create bills, and demonstrate COMMIT/ROLLBACK.
- Database view:
CustomerOrderSummaryto aggregate customer orders. - Stored procedure:
GetBillTotalto calculate order totals. - Input validation and centralized error handling for MySQL exceptions.
MySQL Version / Connector Version
- MySQL Server: 8.0.34
- MySQL Connector/J: 8.1.0
-
Database: Create a MySQL database
restaurant_manager. -
Tables: Ensure the following tables exist:
Customer,Employee,MenuItem,CustomerOrder,OrderItem,Bill,BillLineItem. -
JDBC Driver: Include MySQL Connector/J in your project classpath.
-
Properties: Configure
src/main/resources/app.propertieswith your database URL, username, and password:db.url=jdbc:mysql://localhost:3306/restaurant_manager?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC db.user=root db.password=yourpassword
- Compile and run
Main.java. - The menu displays the following options:
| Option | Action |
|---|---|
| 1 | View Customers |
| 2 | Insert Customer |
| 3 | Update Customer |
| 4 | Delete Customer |
| 5 | View Employees |
| 6 | Insert Employee |
| 7 | View Menu Items |
| 8 | Update Menu Item Price |
| 9 | Run Transaction Demo (Place Order with COMMIT/ROLLBACK) |
| 10 | Create Database View (CustomerOrderSummary) |
| 11 | Create Stored Procedure (GetBillTotal) |
| 0 | Exit |
- Enter the option number to execute an action.
- All inputs are validated; SQL exceptions are handled with clear messages.
Files included:
- Main.java
- create_and_populate.sql
- app.properties
- README.md
- ai_log.md
- Team-roles.txt
- video_demo.mp4
- CustomerOrderSummary:
Combines
CustomerandCustomerOrdertables for quick reporting. ShowsorderID,customerName,totalAmount, andstatus. - Idempotent: can run multiple times without errors.
-
GetBillTotal:
- Input:
orderID - Output:
totalAmount - Calculates the sum of
quantity * unitPricefromOrderItemfor the given order. - Idempotent: can run multiple times without error.
- Input:
Example:
CALL GetBillTotal(2, @total);
SELECT @total;Demonstrates atomicity: all operations succeed together or fail together.
- Create a
CustomerOrder. - Add multiple
OrderItems. - Generate a
Bill. - Add
BillLineItems. - Choose COMMIT or ROLLBACK.
Customer
| Field | Type | Notes |
|---|---|---|
| customerID | BIGINT | Primary Key |
| name | VARCHAR(150) | Customer name |
| contact | VARCHAR(150) | Email/phone |
Employee
| Field | Type | Notes |
|---|---|---|
| employeeID | BIGINT | Primary Key |
| restaurantID | BIGINT | FK to restaurant |
| name | VARCHAR(150) | Employee name |
| role | VARCHAR(80) | Job role |
MenuItem
| Field | Type | Notes |
|---|---|---|
| menuItemID | BIGINT | Primary Key |
| restaurantID | BIGINT | FK to restaurant |
| name | VARCHAR(150) | Item name |
| description | VARCHAR(255) | Item description |
| price | DECIMAL(10,2) | Item price |
CustomerOrder
| Field | Type | Notes |
|---|---|---|
| orderID | BIGINT | Primary Key |
| restaurantID | BIGINT | FK |
| customerID | BIGINT | FK |
| employeeID | BIGINT | FK |
| orderDateTime | DATETIME | Timestamp |
| status | VARCHAR(20) | OPEN/IN_PROGRESS/COMPLETED |
| totalAmount | DECIMAL(10,2) | Order total |
OrderItem
| Field | Type | Notes |
|---|---|---|
| orderID | BIGINT | FK to CustomerOrder |
| menuItemID | BIGINT | FK to MenuItem |
| quantity | INT | Quantity ordered |
| unitPrice | DECIMAL(10,2) | Price per unit |
Bill
| Field | Type | Notes |
|---|---|---|
| billID | BIGINT | Primary Key (matches orderID) |
| orderID | BIGINT | FK |
| issuedAt | DATETIME | Timestamp |
| status | VARCHAR(20) | ISSUED/PAID |
| totalAmount | DECIMAL(10,2) | Total |
BillLineItem
| Field | Type | Notes |
|---|---|---|
| orderID | BIGINT | FK |
| billID | BIGINT | FK |
| lineNum | INT | Line number |
| menuItemID | BIGINT | FK |
| quantity | INT | Quantity |
| unitPrice | DECIMAL(10,2) | Price per unit |
- All operations are validated to prevent SQL errors and invalid input.
- Transaction demo ensures atomic operations.
- Views and stored procedures are idempotent.
- Suitable for demonstration, learning, and extending with more restaurant features.













