-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholympicDB.java
More file actions
237 lines (198 loc) · 7.33 KB
/
olympicDB.java
File metadata and controls
237 lines (198 loc) · 7.33 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import java.util.NoSuchElementException;
import java.util.Properties;
import java.sql.*;
import java.util.Scanner;
public class olympicDB{
private static Connection connection;
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args){
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException err) {
System.err.println("Unable to detect the JDBC .jar dependency. Check that the library is correctly loaded in and try again.");
System.exit(-1);
}
displayOptions();
scanner.close();
}
private static void displayOptions() {
while (true) {
System.out.println("1. Connect to Database");
System.out.println("2. Create Account");
System.out.println("3. Delete Account");
System.out.println("4. Add Participant");
System.out.println("5. Delete Participant");
System.out.println("6. Add Team Member");
System.out.println("7. Remove Team Member");
System.out.println("8. Register Team");
System.out.println("9. Add Event");
System.out.println("10. Add Team to Event");
System.out.println("11. Add Event Outcome");
System.out.println("12. Disqualify Team");
System.out.println("13. List Venues in Olympiad");
System.out.println("14. List Events of Olympiad");
System.out.println("15. List Teams In Event");
System.out.println("16. Show Placements in Event");
System.out.println("17. List Participants on Team");
System.out.println("18. Country Rankings");
System.out.println("19. Top Sports");
System.out.println("21. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
switch (choice) {
case 1:
connect();
break;
case 2:
createAccount();
break;
case 3:
deleteAccount()
break;
case 4:
addParticipant();
break;
case 5:
deleteParticipant();
break;
case 6:
addTeamMember();
break;
case 7:
removeTeamMember();
break;
case 8:
registerTeam();
break;
case 9:
addEvent();
break;
case 10:
addTeamToEvent();
break;
case 11:
addEventOutcome();
break;
case 12:
disqualifyTeam();
break;
case 13:
listVenuesInOlympiad();
break;
case 14:
listEventsInOlympiad();
break;
case 15:
listTeamsInEvent();
break;
case 16:
showPlacementsInEvent();
break;
case 17:
listParticipantsOnTeam();
break;
case 18:
countryRankings();
break;
case 19:
topSports();
break;
case 21:
exit();
break;
default:
System.out.println("Invalid");
}
}
}
private static void connect(){
String url = "jdbc:postgresql://localhost:5432/";
Properties props = new Properties();
try {
System.out.println("Enter username ");
String username = scanner.nextLine();
System.out.println("Enter password: ");
String password = scanner.nextLine();
props.setProperty("user", username);
props.setProperty("password", password);
props.setProperty("escapeSyntaxCallMode", "callIfNoReturn");
} catch (NoSuchElementException ex) {
System.err.println("No lines were read from user input, please try again");
System.exit(-1);
} catch (IllegalArgumentException ex) {
System.err.println("Error");
System.exit(-1);
}
try {
connection = DriverManager.getConnection(url, props);
System.out.println("Successfully connected to Databse!");
} catch (SQLException err) {
System.out.println("SQL Error");
while (err != null) {
System.out.println("Message = " + err.getMessage());
System.out.println("SQLState = " + err.getSQLState());
System.out.println("SQL Code = " + err.getErrorCode());
err = err.getNextException();
}
}
}
private static void createAccount(){
System.out.println("Enter username: ");
String user_name = scanner.nextLine();
System.out.println("Enter passkey: ");
String passkey = scanner.nextLine();
System.out.println("Enter role: ");
String role = scanner.nextLine();
try(CallableStatement createAccount = connection.prepareCall("SELECT olympicDB.createAccount(?, ?, ?)")){
createAccount.setString(1, user_name);
createAccount.setString(2, passkey);
createAccount.setString(3, role);
createAccount.execute();
System.out.println("Account added");
}catch (SQLException e) {
System.out.println("SQL Error: " + e);
for (SQLException ex = e; ex != null; ex = ex.getNextException()) {
if (ex != null) {
System.out.println("Message = " + ex.getMessage());
System.out.println("SQLState = " + ex.getSQLState());
System.out.println("SQL Code = " + ex.getErrorCode());
}
}
}
}
private static void deleteAccount(){
}
private static void addParticipant(){
}
private static void deleteParticipant(){
}
private static void addTeamMember(){
}
private static void removeTeamMember(){
}
private static void registerTeam(){
}
private static void addEvent(){
}
private static void addTeamToEvent(){
}
private static void addEventOutcome(){
}
private static void disqualifyTeam(){
}
private static void listVenuesInOlympiad(){
}
private static void listEventsInOlympiad(){
}
private static void listTeamsInEvent(){
}
private static void showPlacementsInEvent(){
}
private static void listParticipantsOnTeam(){
}
private static void countryRankings(){
}
private static void topSports(){
}
}