Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.example.schedulerapp;
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;
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);
}
/*
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");
}
}