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; protected Positions positions; 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); this.positions = new Positions(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"); } }