Skip to content

COMP3005: Assignment 3 - Q(1) - Database Interaction with PostgreSQL and Application Programming

Notifications You must be signed in to change notification settings

Samimnif/COMP3005-A3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assignment 3 Q(1)

Author

Sami Mnif - 101199669

Video Demo Link

YouTube: https://youtu.be/VolAEBK_Qe4

Details

Table Creation

For this Assignment, we need to create a database and initialize it with some data. We use postgresql to create a Database called "Assignment3-Q1". We then use the following schema to create a table called "students"

CREATE TABLE students (
    student_id SERIAL,
    first_name VARCHAR(255) NOT NULL,
    last_name VARCHAR(255) NOT NULL,
	email VARCHAR(255) NOT NULL,
	enrollment_date DATE,
    Primary Key (student_id)
);

We then initialize the table with some data provided:

INSERT INTO students (first_name, last_name, email, enrollment_date) VALUES
('John', 'Doe', 'john.doe@example.com', '2023-09-01'),
('Jane', 'Smith', 'jane.smith@example.com', '2023-09-01'),
('Jim', 'Beam', 'jim.beam@example.com', '2023-09-02');

Application Functions

In the Main.java file, we created functions that INSERT, UPDATE, and DELETE information to the students table.

  • getAllStudents(): Retrieves and displays all records from the students table.
  • addStudent(first_name, last_name, email, enrollment_date): Inserts a new student record into the students table.
  • updateStudentEmail(student_id, new_email): Updates the email address for a student with the specified student_id.
  • deleteStudent(student_id): Deletes the record of the student with the specified student_id.

Usage

Run the main in the Main.java file, edit according to your needs

public static void main(String[] args) {
        Main main = new Main();
        main.getAllStudents();
        //main.addStudent("Sami", "Mnif", "sami_email@carleton.ca", "2020-05-01");
        //main.updateStudentEmail(4, "samimnif@sce.com");
        main.deleteStudent(4);
        main.getAllStudents();
    }

Copyright

© Copyright 2024 - Sami Mnif - COMP 3005

About

COMP3005: Assignment 3 - Q(1) - Database Interaction with PostgreSQL and Application Programming

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages