-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSignUpSQL.java
193 lines (175 loc) · 6.66 KB
/
SignUpSQL.java
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
import java.sql.*;
import java.sql.Date;
import java.text.ParseException;
import java.sql.SQLException;
public class SignUpSQL {
//This connects to the database by calling the login file
static Connection connection = Login.connection;
static Statement statement = Login.statement;
static ResultSet result = Login.result;
/**
* Method is called in SignUp file where user wants to see all the SignUps in the database. This method
* will perform the sql statement and generate a result set of all the SignUps in the database.
* @return ResultSet
* @throws ClassNotFoundException
* @throws SQLException
* @throws ParseException
*/
public static ResultSet viewAllSignUps() throws ClassNotFoundException, SQLException, ParseException{
//A table of data representing a database result set, which is usually generated by executing a
//statement that queries the database.
ResultSet returnSet = null;
//Object that represents a precompiled SQL statement
PreparedStatement ps = null;
try {
ps = connection.prepareStatement("SELECT * FROM SignUp;");
returnSet = ps.executeQuery();
ps.close();
} catch (SQLException e) {
System.out.println("SQL Exception");
e.printStackTrace();
return null;
}
return returnSet;
}
/**
* Method is called in the SignUp file and is used to find a specific SignUp.
* @param memberID
* @return ResultSet
* @throws ClassNotFoundException
* @throws SQLException
* @throws ParseException
*/
public static ResultSet viewSignUp(int memberID) throws ClassNotFoundException, SQLException, ParseException{
//A table of data representing a database result set, which is usually generated by executing a
//statement that queries the database.
ResultSet returnSet = null;
//Object that represents a precompiled SQL statement
PreparedStatement ps = null;
try {
ps = connection.prepareStatement("SELECT * FROM SignUp WHERE memberID = ?;");
ps.setInt(1, memberID);
returnSet = ps.executeQuery();
ps.close();
} catch (SQLException e) {
System.out.println("SQL Exception");
e.getStackTrace();
return null;
}
return returnSet;
}
/**
* Method is called from SignUp file and is called after the user has finished filling all the attributes for a SignUp
* @param storeID
* @param signUpDate
* @param staffID
* @param memberID
* @throws SQLException
* @throws ParseException
*/
static void addSignUp(int storeID, Date signUpDate, int staffID, int memberID) throws SQLException, ParseException{
//Object that represents a precompiled SQL statement
PreparedStatement ps = null;
int id = 0;
try{
ps = connection.prepareStatement("INSERT INTO SignUp (storeID, signUpDate, staffID, memberID) VALUES (?,?,?,?);");
ps.setInt(1,storeID);
ps.setDate(2,signUpDate);
ps.setInt(3,staffID);
ps.setInt(4,memberID);
id = ps.executeUpdate();
connection.commit();
ps.close();
System.out.println(id);
if(id > 0){
System.out.println("SignUp added successfully");
} else{
System.out.println("SignUp not added");
}
}
catch (SQLException e) {
System.out.println("SQL Exception");
connection.rollback();
e.printStackTrace();
}
}
/**
* Method is called from SignUp file and is called after the user has finished filling all the attributes that they want to edit
* for a SignUp
* @param storeID
* @param signUpDate
* @param staffID
* @param memberID
* @throws SQLException
* @throws ParseException
*/
static void editSignUp(int storeID, Date signUpDate, int staffID, int memberID) throws SQLException, ParseException{
//Object that represents a precompiled SQL statement
PreparedStatement ps = null;
int id = 0;
try{
ps = connection.prepareStatement("UPDATE SignUp SET storeID = ?, signUpDate = ?, staffID = ? WHERE memberID = ?;");
ps.setInt(1,storeID);
ps.setDate(2,signUpDate);
ps.setInt(3,staffID);
ps.setInt(4,memberID);
id = ps.executeUpdate();
connection.commit();
ps.close();
System.out.println(id);
if(id > 0){
System.out.println("SignUp updated successfully");
} else{
System.out.println("SignUp not updated");
}
}
catch (SQLException e) {
System.out.println("SQL Exception");
connection.rollback();
e.printStackTrace();
}
}
/**
* Method is called from SignUp file and is called to delete a SignUp from the database
* @param memberID
*/
static void deleteSignUp(int memberID){
try {
PreparedStatement ps = connection.prepareStatement("DELETE FROM SignUp WHERE memberID = ?;");
ps.setInt(1, memberID);
int id = ps.executeUpdate();
System.out.println(id);
if (id > 0) {
System.out.println("SignUp deleted");
} else {
System.out.println("SignUp not deleted");
}
} catch (SQLException e) {
System.out.println("SQL Exception");
e.printStackTrace();
}
}
public static ResultSet growthReport(boolean isStore, int storeID, String start, String end) throws ClassNotFoundException, SQLException, ParseException
{
ResultSet returnSet = null;
PreparedStatement ps = null;
try {
if (isStore) {
ps = connection.prepareStatement("SELECT COUNT(memberID) FROM SignUp WHERE storeID = ? AND signUpDate BETWEEN ? AND ?;");
ps.setInt(1, storeID);
ps.setString(2, start);
ps.setString(3, end);
} else {
ps = connection.prepareStatement("SELECT COUNT(memberID) FROM SignUp WHERE signUpDate BETWEEN ? AND ?;");
ps.setString(1, start);
ps.setString(2, end);
}
returnSet = ps.executeQuery();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
return null;
}
return returnSet;
}
}