-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckProjNums.java
More file actions
54 lines (47 loc) · 1.54 KB
/
CheckProjNums.java
File metadata and controls
54 lines (47 loc) · 1.54 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
package poised;
import java.sql.*;
import java.util.ArrayList;
/**
* Responsible for checking if a <code>proj_num</code> of the Project table
* exists.
*
* @author Nadia
* @Version 2.0
* @Since 1 June 2022
*
*/
public abstract class CheckProjNums {
/**
* Creates an ArrayList of the <code>proj_num</code> of all the records
* in the project table and checks if user input matches one of them.
* Used to validate that a <code>proj_num</code> is unique when a new
* project is being created.
*
* @param userEntry a String of the project number to be checked
* @return <code>true</code> if the <code>userEntry</code>
* matched to a project number already in the
* database, or <code><false</code> if not.
* @throws SQLException JDBC API error
*/
public static boolean isProjNumInDatabase(String userEntry)
throws SQLException {
// establish connection to the DB
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/PoisePMS?useSSL=false",
"otheruser",
"swordfish");
Statement statement = connection.createStatement();
// request results of all columns from the table
ResultSet tableInfo = statement.executeQuery(
"SELECT proj_num FROM project");
// create an ArrayList of id numbers to check if user input is there
ArrayList<String> projNums = new ArrayList<>();
while (tableInfo.next()) {
projNums.add(tableInfo.getString(1));
}
// close DB connection
connection.close();
statement.close();
return (projNums.contains(userEntry));
}
}