-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeal.java
More file actions
98 lines (96 loc) · 3.24 KB
/
Meal.java
File metadata and controls
98 lines (96 loc) · 3.24 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
package PAT;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
Class Meal
Backend of the MealGUI class and used to communicate with the database
*/
public class Meal extends DBConnect{
String sql = ""; //Contains the SQL that will be executed
ResultSet rs; //Contains resultset of the data retrieved from the database
/*
Method getRecipNames
Returns all the recipe names in the datbase of a certain type
@parameters: String recipe type
@return: Resultset recipe names
*/
public ResultSet getRecipeNames(String type) throws SQLException{
sql = "SELECT recipeName FROM tblRecipes WHERE recipeType = '" + type +"';";
return query(sql);
}
/*
Method getIngredients
Retrieves all the ingredients needed to complete a recipe
@parameters: String recipe ID
@return: Resultset needed ingredients
*/
public ResultSet getIngredients(String ID) throws SQLException{
sql = "SELECT tblIngredients.itemID, tblIngredients.inQuantity " +
"FROM tblIngredients " +
"INNER JOIN tblRecipes " +
"ON tblRecipes.recipeID = tblIngredients.recipeID " +
"WHERE tblRecipes.recipeID = "+ ID + ";";
return query(sql);
}
/*
Method getRecipeID
Gets the recipe ID of the name provided as input
@parameters: String recipe name
@return: none
*/
public String getRecipeID(String recipeName){
String ID = "";
try {
sql ="SELECT recipeID FROM tblRecipes WHERE recipeName = '" + recipeName +"';";
rs = query(sql);
if(rs.next()){
//extract recipe ID
ID = rs.getString("recipeID");
}
} catch (SQLException ex) {
Logger.getLogger(Meal.class.getName()).log(Level.SEVERE, null, ex);
}
return ID;
}
/*
Method getAthleteAmount
Gets the total amount of athletes in the hostel
@parameters: none
@return: int amount of athletes
*/
public int getAthleteAmount(){
int amount = 0;
try {
sql ="SELECT COUNT(*) AS amountOfAthletes\n" +
"FROM tblAthlete;";
rs = query(sql);
if(rs.next()){
//extract total amount of athletes from the resultset
amount = rs.getInt("amountOfAthletes");
}
} catch (SQLException ex) {
Logger.getLogger(Meal.class.getName()).log(Level.SEVERE, null, ex);
}
return amount;
}
/*
Method getItemName
Retrieves the name of an item based on the ID provided
*/
public String getItemName(String ID){
String iName = "";
try {
sql ="SELECT itemName FROM tblInventory WHERE itemID = " + ID +";";
rs = query(sql);
if(rs.next()){
// extract item name
iName = rs.getString("itemName");
}
} catch (SQLException ex) {
Logger.getLogger(Meal.class.getName()).log(Level.SEVERE, null, ex);
}
return iName;
}
}