-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct_update.java
More file actions
331 lines (250 loc) · 8.57 KB
/
product_update.java
File metadata and controls
331 lines (250 loc) · 8.57 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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JTextField;
import java.awt.Rectangle;
import javax.swing.SwingConstants;
import javax.swing.JTextArea;
import javax.swing.JSeparator;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;
import java.awt.Color;
public class product_update {
public JFrame frmAmElectronics;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
product_update window = new product_update();
window.frmAmElectronics.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public product_update() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmAmElectronics = new JFrame();
frmAmElectronics.setTitle("AM ELECTRONICS");
frmAmElectronics.getContentPane().setBackground(new Color(51, 51, 153));
frmAmElectronics.setBounds(100, 100, 846, 487);
frmAmElectronics.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmAmElectronics.getContentPane().setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(new Color(51, 51, 153));
panel.setLayout(null);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
panel.setBounds(10, 11, 655, 438);
frmAmElectronics.getContentPane().add(panel);
JLabel label = new JLabel("Product No");
label.setForeground(new Color(255, 255, 255));
label.setFont(new Font("Cambria", Font.BOLD, 13));
label.setBounds(63, 55, 82, 21);
panel.add(label);
JLabel lblProductUpdateForm = new JLabel("Product Update Form");
lblProductUpdateForm.setForeground(new Color(255, 255, 255));
lblProductUpdateForm.setFont(new Font("Cambria", Font.BOLD, 15));
lblProductUpdateForm.setBounds(189, 11, 168, 21);
panel.add(lblProductUpdateForm);
JComboBox<String> c1 = new JComboBox<String>();
c1.setBounds(211, 55, 116, 22);
panel.add(c1);
JComboBox<String> c2 = new JComboBox<String>();
c2.setBounds(211, 84, 116, 22);
panel.add(c2);
JComboBox<String> c3 = new JComboBox<String>();
c3.setBounds(211, 157, 116, 22);
panel.add(c3);
JComboBox<String> c4 = new JComboBox<String>();
c4.setBounds(211, 192, 116, 22);
panel.add(c4);
JLabel lblApplianceName = new JLabel("Appliance Name");
lblApplianceName.setForeground(new Color(255, 255, 255));
lblApplianceName.setFont(new Font("Cambria", Font.BOLD, 13));
lblApplianceName.setBounds(63, 160, 116, 14);
panel.add(lblApplianceName);
JLabel label_5 = new JLabel("Brand Name");
label_5.setForeground(new Color(255, 255, 255));
label_5.setFont(new Font("Cambria", Font.BOLD, 13));
label_5.setBounds(63, 195, 82, 14);
panel.add(label_5);
JTextArea textArea = new JTextArea();
textArea.setBounds(251, 112, -94, 39);
panel.add(textArea);
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
Statement stmt = conObject.createStatement();
String query = "Select pid from Actual_product";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
c1.addItem(rs.getString(1));
}
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int resp = JOptionPane.showConfirmDialog(null, "Are you sure you want to update?");
if(resp == 0)
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
String supp=String.valueOf(c1.getSelectedItem());
String query = "update supplier set sname=?,saddr=?,scon=?,email=? where sno="+Integer.parseInt(supp);
PreparedStatement stmt = conObject.prepareStatement(query);
ResultSet rs = stmt.executeQuery(query);
c2.addItem(rs.getString(1));
c3.addItem(rs.getString(2));
c4.addItem(rs.getString(3));
int result = stmt.executeUpdate();
if(result == 1)
JOptionPane.showMessageDialog(null, "Record updated successfully!");
else
JOptionPane.showMessageDialog(null,"Insert Error!");
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
}
});
btnUpdate.setFont(new Font("Cambria", Font.BOLD, 14));
btnUpdate.setBounds(63, 282, 108, 23);
panel.add(btnUpdate);
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
Statement stmt = conObject.createStatement();
String query = "Select aname from app";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
c3.addItem(rs.getString(1));
}
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
JButton button_2 = new JButton("Exit");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int resp = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?");
if(resp == 0)
{
System.exit(1);
MDI1 frame1 = new MDI1();
frame1.frmAmEletronics.setVisible(true);
}
}
});
button_2.setFont(new Font("Cambria", Font.BOLD, 14));
button_2.setBounds(291, 282, 108, 23);
panel.add(button_2);
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
Statement stmt = conObject.createStatement();
String query = "Select modelname from Actual_product";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
c2.addItem(rs.getString(1));
}
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
JSeparator separator = new JSeparator();
separator.setBounds(63, 42, 393, 2);
panel.add(separator);
JSeparator separator_1 = new JSeparator();
separator_1.setBounds(63, 250, 405, 2);
panel.add(separator_1);
JLabel lblProductName = new JLabel("Product Name");
lblProductName.setForeground(new Color(255, 255, 255));
lblProductName.setFont(new Font("Cambria", Font.BOLD, 13));
lblProductName.setBounds(63, 87, 116, 14);
panel.add(lblProductName);
JButton btnShow = new JButton("Show");
btnShow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
String supp=String.valueOf(c1.getSelectedItem());
String query = "select * from Actual_product where pid="+Integer.parseInt(supp);
PreparedStatement stmt = conObject.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
if(rs.next())
{
c2.addItem(rs.getString(1));
c3.addItem(rs.getString(1));
c4.addItem(rs.getString(1));
}
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
});
btnShow.setFont(new Font("Cambria", Font.BOLD, 14));
btnShow.setBounds(360, 55, 108, 23);
panel.add(btnShow);
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
Statement stmt = conObject.createStatement();
String query = "Select bname from brand";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
c4.addItem(rs.getString(1));
}
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
}