Welcome to this hands-on Database Workshop Assignment!
This exercise will help you understand how to connect to a PostgreSQL database and perform the basic CRUD operations (Create, Read, Update, Delete) through a simple Java project.
You'll be working with two tables: Clubs and Players.
.
βββ DatabaseManager.java # Handles PostgreSQL connection and query execution
βββ models/
β βββ player.java # Player model and related DB operations
β βββ club.java # Club model and related DB operations
βββ main.java # Entry point to execute all database tasksUse the provided model files or your own SQL commands to create two tables:
clubswith fields likeid,title,managerplayerswith fields likeid,fullName,clubId(foreign key)
Insert the following two clubs into the clubs table:
| Name | Manager |
|---|---|
| Real Madrid | Ancelotti |
| Liverpool | Slot |
Add the following four players to the players table all at once (i.e., in a single insert statement):
| Name | Club |
|---|---|
| Jude Bellingham | Real Madrid |
| Valverde | Real Madrid |
| Alexander-Arnold | Liverpool |
| Courtois | Real Madrid |
Use SELECT statements to print the current data from both clubs and players tables to verify your inserts.
- Update Alexander-Arnold's team from Liverpool to Real Madrid
- Update Real Madrid's manager from Ancelotti to Alonso
View the data again to confirm your updates have taken effect.
- Delete Jude Bellingham from the
playerstable - Delete Liverpool from the
clubstable (ensure foreign key constraints are handled)
Perform one last SELECT on both tables to view the final state of your database.
- Java JDK
- PostgreSQL
- JDBC Driver
- Wrap database operations in
try-exceptblocks for error handling - Always close your DB connection!
By the end of this assignment, you should be confident in:
- Structuring code to interact with a database
- Performing all core SQL operations from Java
- Understanding table relationships and foreign keys
Feel free to open an issue or ask during the workshop!
Happy Coding! π