Skip to content
Snippets Groups Projects
DataBaseQuery.java 1.73 KiB
Newer Older
  • Learn to ignore specific revisions
  • package com.example.scheduler_server;
    
    
    import java.sql.*;
    
    /*
        Name: DataBaseQuery
        Description: Makes the connection to the database, and sends the connection to the Staff and Schedule after
        initializing them.
     */
    public class DataBaseQuery {
        protected Staff staff;
        protected Schedule schedule;
    
        protected TimeOff timeOff;
        protected Availability availability;
    
        private Connection dbConnection;
    
        /*
        Name: DataBaseQuery
        Parameters:
            String dbURL: The URL of the database
            String dbUser: The username of the database.
            String dbPass: The password of the database.
        Description: Calls connectDataBase and initializes the Staff and Schedule.
        Return: DataBaseQuery
         */
        public DataBaseQuery(String dbURL, String dbUser, String dbPass){
            connectDataBase(dbURL, dbUser, dbPass);
            this.staff = new Staff(dbConnection);
            this.schedule = new Schedule(dbConnection);
    
            this.timeOff = new TimeOff(dbConnection);
            this.availability = new Availability(dbConnection);
    
        }
    
        /*
        Name: connectDataBase
        Parameters:
            String dbURL: The URL of the database
            String dbUser: The username of the database.
            String dbPass: The password of the database.
        Description: Establishes the connection to the database.
        Return: void
         */
        protected void connectDataBase(String dbURL, String dbUser, String dbPass){
            try {
                dbConnection = DriverManager.getConnection(dbURL, dbUser, dbPass);
            } catch (Exception exception) {
                System.out.println("Failed to connect to the database");
                exception.printStackTrace();
            }
            System.out.println("Successfully connected to the database");
        }
    
    }