-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduleQueries.java
More file actions
93 lines (73 loc) · 3.6 KB
/
Copy pathScheduleQueries.java
File metadata and controls
93 lines (73 loc) · 3.6 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package courseschedulerjakebyrnep1;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
*
* @author jakebyrne
*/
public class ScheduleQueries {
private static Connection connection;
private static PreparedStatement addScheduleEntry;
private static PreparedStatement getScheduleByStudent;
private static ResultSet scheduleByStudentRslt;
private static PreparedStatement getScheduledStudentCount;
private static ResultSet scheduledStudentCountRslt;
public static int getScheduledStudentCount(String currentSemester, String courseCode) {
int count = 0;
try {
connection = DBConnection.getConnection();
getScheduledStudentCount = connection.prepareStatement("SELECT count(studentid) FROM app.schedule WHERE semester = ? OR coursecode = ?");
getScheduledStudentCount.setString(1, currentSemester);
getScheduledStudentCount.setString(2, courseCode);
scheduledStudentCountRslt = getScheduledStudentCount.executeQuery();
scheduledStudentCountRslt.next();
count = scheduledStudentCountRslt.getInt(1);
} catch(SQLException sqlException)
{
sqlException.printStackTrace();
}
System.out.println("studentNum" + count);
return count;
}
public static void addScheduleEntry(ScheduleEntry entry) {
try {
connection = DBConnection.getConnection();
addScheduleEntry = connection.prepareStatement(
"INSERT INTO app.schedule(semester, studentid, coursecode, status, timestamp) VALUES (?, ?, ?, ?, ?)");
addScheduleEntry.setString(1, entry.getSemester());
addScheduleEntry.setString(3, entry.getCourseCode());
addScheduleEntry.setString(2, entry.getStudentID());
addScheduleEntry.setString(4, entry.getStatus());
addScheduleEntry.setTimestamp(5, entry.getTimestamp());
addScheduleEntry.executeUpdate();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
}
}
public static ArrayList<ScheduleEntry> getScheduleByStudent(String semester, String studentID) {
ArrayList<ScheduleEntry> studentSchedule = new ArrayList<>();
try {
connection = DBConnection.getConnection();
getScheduleByStudent = connection.prepareStatement("SELECT semester, coursecode, studentid, status, timestamp FROM app.schedule WHERE semester = ? OR studentid = ?");
getScheduleByStudent.setString(1, semester);
getScheduleByStudent.setString(2, studentID);
scheduleByStudentRslt = getScheduleByStudent.executeQuery();
while(scheduleByStudentRslt.next()) {
ScheduleEntry studentScheduleObj = new ScheduleEntry(scheduleByStudentRslt.getString(1), scheduleByStudentRslt.getString(2), scheduleByStudentRslt.getString(3), scheduleByStudentRslt.getString(4), scheduleByStudentRslt.getTimestamp(5));
studentSchedule.add(studentScheduleObj);
}
} catch(SQLException sqlException)
{
sqlException.printStackTrace();
}
//CONFIRMED ISSUE IS HERE NOTHING IS COMING OUT FROM
return studentSchedule;
}
}