Dagim H.#1
Conversation
There was a problem hiding this comment.
I really like how focused and minimal this PR is. By only including the necessary files, the solution is easy to review and the intent is immediately clear. This is a great example of the KISS principle in practice: simple, purposeful, and without unnecessary noise. It takes confidence to keep things this lean, and I think that deserves recognition.
|
|
||
| // Publisher 2 rows | ||
| PreparedStatement pub = conn.prepareStatement( | ||
| "INSERT INTO publishers (name) VALUES (?) ON CONFLICT (name) DO NOTHING" |
There was a problem hiding this comment.
Nice that you try to avoid duplicate insert errors using ON CONFLICT DO NOTHING. That makes the seed data easier to rerun during development. One thing to watch out for is that the code still uses hardcoded IDs afterwards. For example, if the publisher already exists with a different publisher_id, then using 1 as the hardcoded publisher_id can cause problems later on.
One way to avoid this is to return the actual ID from the database:
INSERT INTO publishers (name)
VALUES (?)
ON CONFLICT (name)
DO UPDATE SET name = EXCLUDED.name
RETURNING publisher_id;
Then you can use the publisher_id returned by the query to set the foreign keys later on.
complete:
task‑1: Normalized the raw library export into a clean 3NF schema. Designed tables, relationships (1:1, 1:N, N:M), added all required constraints, and successfully executed schema.sql to create and run the library_db.
task‑2: Implemented a JDBC-based console application for the library database. Added insertData() to populate tables with sample rows and fetchData() using a JOIN query to retrieve borrowing records.
Fully tested database connection and CRUD operations.