-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInsertData.java
211 lines (167 loc) · 6.82 KB
/
InsertData.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import Log.*;
import Item.*;
import Notif.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.SQLException;
public class InsertData {
private static Kettlelog kettle = new Kettlelog();
InsertData(){
}
public void insertinfo(String id, String name, String status,
String quantity, String minimum, String delivery, String desc,
int starbool, String dateadded, String adc, String rop, String rod) {
String command = "INSERT INTO info(id, name, status, quantity, minimumstock, deliverytime, description, starred, dateadded, adc, rop, rod) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
try {
//Connect to our database, so then we can access the tables in there directly
String filename = id + ".db";
Connection conn = kettle.getDataBase(filename);
PreparedStatement v = conn.prepareStatement(command);
//Setting our insertion values here.
v.setString(1, id);
v.setString(2, name);
v.setString(3, status);
v.setString(4, quantity);
v.setString(5, minimum);
v.setString(6, delivery);
v.setString(7, desc);
v.setInt(8, starbool);
v.setString(9, dateadded);
v.setString(10, adc);
v.setString(11, rop);
v.setString(12, rod);
v.executeUpdate();
v.close();
conn.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
//We need the name parameter here to specify which database to connect to.
public void insertlogs(String itemid, String logid, String logtype, String logdate, String logquan) {
String command = "INSERT INTO log(logid, logtype, logdate, logquan) VALUES(?,?,?,?)";
try {
String filename = itemid + ".db";
Connection conn = kettle.getDataBase(filename);
PreparedStatement v = conn.prepareStatement(command);
//Setting our insertion values here.
v.setString(1, logid);
v.setString(2, logtype);
v.setString(3, logdate);
v.setString(4, logquan);
v.executeUpdate();
v.close();
conn.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
//This is a method that edits the infotable for a database.
public void editinfo(String id, String name, String status, String quantity,
String minimum, String delivery, String desc, int starbool,
String dateadded, String adc, String rop, String rod) {
String command = "UPDATE info SET name = ?, "
+ "status = ?, "
+ "quantity = ?, "
+ "minimumstock = ?, "
+ "deliverytime = ?, "
+ "description = ?, "
+ "starred = ?, "
+ "dateadded = ?, "
+ "adc = ?, "
+ "rop = ?, "
+ "rod = ? "
+ "WHERE id = " + id;
try {
String filename = id + ".db";
Connection conn = kettle.getDataBase(filename);
PreparedStatement v = conn.prepareStatement(command);
//Editing the values of our row.
v.setString(1, name);
v.setString(2, status);
v.setString(3, quantity);
v.setString(4, minimum);
v.setString(5, delivery);
v.setString(6, desc);
v.setInt(7, starbool);
v.setString(8, dateadded);
v.setString(9, adc);
v.setString(10, rop);
v.setString(11, rod);
v.executeUpdate();
v.close();
conn.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
//This is a method that deletes a log from logtable for a database.
public void removeLog(String id, String logid) {
String command = "DELETE FROM log WHERE logid = ?";
try {
String filename = id + ".db";
Connection conn = kettle.getDataBase(filename);
PreparedStatement v = conn.prepareStatement(command);
v.setString(1, logid);
v.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public void addNotification(Notif notif){
String message = notif.getMessage();
String itemId = notif.getItemId();
int readStatus = notif.getReadStatus();
String notifId = notif.getNotifId();
String dateGenerated = notif.getDateGenerated();
String command = "INSERT INTO notifData(message, itemId, readStatus, notifId, dateGenerated) VALUES(?,?,?,?,?)";
try {
String filename = "notifications.db";
Connection conn = kettle.getDataBase(filename);
PreparedStatement v = conn.prepareStatement(command);
//Setting our insertion values here.
v.setString(1, message);
v.setString(2, itemId);
v.setInt(3, readStatus);
v.setString(4, notifId);
v.setString(5, dateGenerated);
v.executeUpdate();
v.close();
conn.close();
} catch (SQLException e) {
System.out.println("addNotification: "+e.getMessage());
}
}
public void deleteNotif(String notifId){
//System.out.println("Deleting notification with id: "+notifId);
String command = "DELETE FROM notifData WHERE notifId = '" + notifId +"'";
try {
String filename = "notifications.db";
Connection conn = kettle.getDataBase(filename);
Statement stmt = conn.createStatement();
stmt.execute(command);
stmt.close();
conn.close();
} catch (SQLException e) {
System.out.println("deleteNotif: "+e.getMessage());
}
}
public void updateNotifReadStatus(int status, String notifId){
//find file with that id
Connection conn = kettle.getDataBase("notifications.db");
try{
String cmd = "UPDATE notifData SET readStatus = " + status + " WHERE notifId = '" + notifId +"';";
Statement stmt = conn.createStatement();
stmt.execute(cmd);
stmt.close();
conn.close();
System.out.println("updated notif read status for: "+notifId);
}
catch(SQLException e){
System.out.println("UpdateNotifStatus: "+e.getMessage());
}
}
}