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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.example.scheduler_server;
import java.sql.*;
import java.util.Locale;
/*
Name: Positions
Description: Responsible for sending queries and receiving responses from the database that deal with the
Positions table.
*/
public class Positions {
private final Connection dbConnection;
protected Positions(Connection c) {
this.dbConnection = c;
}
protected String addPosition(String position, float wage){
String newPosition = "";
try {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
myStatement.executeUpdate("insert into Positions (position, wage) " +
"values ('" + position.toLowerCase(Locale.ROOT) +"', "+ wage + ")");
ResultSet myRs = myStatement.executeQuery("select * from Positions where position=" + position);
newPosition = myRs.getString("position") + "/" + myRs.getString("wage");
} catch (SQLException exception) {
exception.printStackTrace();
return newPosition;
}
return newPosition;
}
protected String editPosition(String position, float newWage){
String editedPosition = "";
try {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
myStatement.executeUpdate("update Positions set wage=" + newWage +
"where position='" + position.toLowerCase(Locale.ROOT) +"'");
ResultSet myRs = myStatement.executeQuery("select * from Positions where position=" + position);
editedPosition = myRs.getString("position") + "/" + myRs.getString("wage");
} catch (SQLException exception) {
exception.printStackTrace();
return editedPosition;
}
return editedPosition;
}
protected void removePosition(String position){
try {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
myStatement.executeUpdate("delete from Positions " +
"where position = '" + position.toLowerCase(Locale.ROOT) + "'");
} catch (SQLException exception) {
exception.printStackTrace();
}
}
protected String allPositions(){
StringBuilder response = new StringBuilder("allPositions");
try {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("select * from Positions");
while (myRs.next()) {
response.append("/").append(myRs.getString("position"))
.append(",").append(myRs.getString("wage"));
}
} catch (SQLException exception) {
exception.printStackTrace();
}
return response.toString();
}
}