-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAdmin.java
More file actions
737 lines (708 loc) · 36.2 KB
/
Admin.java
File metadata and controls
737 lines (708 loc) · 36.2 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
//package Connection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
import java.sql.*;
public class Admin {
Scanner sc=new Scanner(System.in);
public int admin_login(Connection con) {
try {
Statement stmt=con.createStatement();
try {
System.out.println("**************************************************");
System.out.println(" Enter User id:");
System.out.println();
String loginid=sc.next();
System.out.println("**************************************************");
System.out.println(" Enter Password:");
System.out.println();
System.out.println("**************************************************");
String password=sc.next();
ResultSet rs=stmt.executeQuery("select * from admin where admin_userid='"+loginid+"'"+ "and admin_password='"+password+"'");
boolean isnotEmpty = rs.first();
if(isnotEmpty) {
stmt.close();
// System.out.println("Login Successfull");
return 1;//logged in successfully
}
else{return 0;}// not able to login
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
public void edit_supplier(Connection con)
{
try {
Statement stmt=con.createStatement();
try
{
System.out.println(" __________________________________________________");
System.out.println("|===================================================|");
System.out.println("| |");
System.out.println("| Supplier Details |");
System.out.println("| |");
System.out.println("|===================================================|");
System.out.println("|1.View supplier |");
System.out.println("|2.Update or delete a supplier |");
System.out.println("|3.Exit |");
System.out.println(" __________________________________________________");
System.out.println(" Please enter your choice");
int flag=sc.nextInt();
if(flag==1) //View Product
{
System.out.println("*******************************************************************************************************");
System.out.println(" List of suppliers" );
System.out.println("*******************************************************************************************************");
ResultSet rs=stmt.executeQuery("select * from supplier" );
System.out.print("SupplierID " + "Supplier Name "+ "Pin Code " + " Contact Number" + "Country Code" +" Supplier Rating:");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("supplier_id")+" "+rs.getString("supplier_name")+" "+rs.getString("pin_code")+" "+rs.getString("contact_number")+" "+rs.getString("country_code")+" "+rs.getString("supplier_rating"));
}
System.out.println("********************************************************************************************************");
// int w=sc.nextInt();
// return 1;
}
else if(flag==2) //Update and delete
{
System.out.println("**************************************************");
System.out.println(" Update and Delete");
System.out.println("**************************************************");
ResultSet rs=stmt.executeQuery("select * from supplier" );
System.out.print("SupplierID " + "Supplier Name "+ "Pin Code " + " Contact Number" + "Country Code" +" Supplier Rating:");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("supplier_id")+" "+rs.getString("supplier_name")+" "+rs.getString("pin_code")+" "+rs.getString("contact_number")+" "+rs.getString("country_code")+" "+rs.getString("supplier_rating"));
}
System.out.println();
System.out.println("Choose the Supplier ID of the supplier you want to update/remove");
String supplier_id=sc.next();
System.out.println("====================================================");
System.out.println("Press 1 to change supplier name");
System.out.println("Press 2 to change the Supplier User ID");
System.out.println("Press 3 to change the Supplier password");
System.out.println("Press 4 to change the pin code");
System.out.println("Press 5 to change the contact_number");
System.out.println("Press 6 to change the country code");
System.out.println("Press 7 to change the supplier rating");
System.out.println("Press 8 to remove the supplier ");
System.out.println("====================================================");
int choice=sc.nextInt();
if(choice==1)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new name: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update supplier set supplier_name='" + update + "' where supplier_id=" + supplier_id);
}
else if(choice==2)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new user ID: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update supplier set supplier_name='" + update + "' where supplier_id=" + supplier_id);
}
else if(choice==3)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new password: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update supplier set password='" + update + "' where supplier_id=" + supplier_id);
}
else if(choice==4)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new pin code: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update supplier set pin_code='" + update + "' where supplier_id=" + supplier_id);
}
else if(choice==5)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new Contact Number: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update supplier set contact_number='" + update + "' where supplier_id=" + supplier_id);
}
else if(choice==6)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new Country code: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update supplier set country_code='" + update + "' where supplier_id=" + supplier_id);
}
else if(choice==7)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new Supplier Rating: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update supplier set supplier_rating='" + update + "' where supplier_id=" + supplier_id);
}
else if(choice==8)
{
System.out.println(" Deleted Supplier" );
System.out.println("------------------------------------------------");
stmt.executeUpdate("delete from supplier where supplier_id=" + supplier_id);
}
// return 1;
}
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
// return 0;
}
public int edit_products(Connection con)
{
try {
Statement stmt=con.createStatement();
try
{
System.out.println(" __________________________________________________");
System.out.println("|===================================================|");
System.out.println("| |");
System.out.println("| Products Details |");
System.out.println("| |");
System.out.println("|===================================================|");
System.out.println("| 1.View Product |");
System.out.println("| 2.Add Product |");
System.out.println("| 3.Update or delete a product |");
System.out.println("| 4.Exit |");
System.out.println(" __________________________________________________");
System.out.println(" Please enter your choice");
int flag=sc.nextInt();
if(flag==1) //View Product
{
System.out.println("*******************************************************************************************************");
System.out.println(" List of products" );
System.out.println("*******************************************************************************************************");
ResultSet rs=stmt.executeQuery("select * from products" );
System.out.print("ProductID " + " Product Name "+ "Supplier ID " + " Product Price " + "Quantity available " +" Product Rating " + " Category" + " Created At");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("product_id")+" "+rs.getString("product_name")+" "+rs.getString("supplier_id")+" "+rs.getString("product_price")+" "+rs.getString("quantity_available")+" "+rs.getString("product_rating")+" "+rs.getString("category_id")+" "+rs.getString("created_at"));
}
return 1;
}
else if(flag==2) //Add new Product
{
System.out.println("**************************************************");
System.out.println(" Add new Product");
System.out.println("**************************************************");
System.out.println("Please choose a Category ID(Choose a number)");
ResultSet rs=stmt.executeQuery("select category_id, category_name from categories");
while(rs.next()) {
System.out.println("Category ID: "+rs.getString("category_id")+" Category Name:"+rs.getString("category_name"));
}
String category=sc.next();
System.out.println("------------------------------------------------");
System.out.println("Enter Name of the product:"); String product_name=sc.next();
System.out.println("------------------------------------------------");
System.out.println("Enter the product price: "); String price=sc.next();
System.out.println("------------------------------------------------");
System.out.println("Enter Quantity:"); String quantity=sc.next();
System.out.println("------------------------------------------------");
System.out.println("Enter supplier");String supplier=sc.next();
System.out.println("------------------------------------------------");
try {
java.util.Date javaDate = new java.util.Date();
long javaTime = javaDate.getTime();
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(javaTime);
String join=sqlTimestamp.toString();
String query1="INSERT into product (`product_name`,`supplier_id`,`product_price`,`quantity_available`,`created_at`,`category_id`)";
String query2="VALUES ('"+product_name+"','"+supplier+"','"+price+"','"+quantity+"','"+join+"','"+category+"')";
String final_query=query1+query2;
stmt.executeUpdate(final_query);
stmt.close();
return 1;
}
catch(Exception e) {
System.out.println(e);
}
stmt.close();
return 1;
}
else if(flag==3) //Update and delete
{
System.out.println("**************************************************");
System.out.println(" Update and Delete");
System.out.println("**************************************************");
System.out.println("Products List");
ResultSet rs=stmt.executeQuery("select * from products" );
System.out.print("ProductID " + " Product Name "+ "Supplier ID " + " Product Price " + "Quantity available " +" Product Rating " + " Category" + " Created At");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("product_id")+" "+rs.getString("product_name")+" "+rs.getString("supplier_id")+" "+rs.getString("product_price")+" "+rs.getString("quantity_available")+" "+rs.getString("product_rating")+" "+rs.getString("category_id")+" "+rs.getString("created_at"));
}
System.out.println("Choose the Product ID of product you want to update/remove");
String product_id=sc.next();
System.out.println("====================================================");
System.out.println(" Press 1 to change product name");
System.out.println(" Press 2 to change the product price");
System.out.println(" Press 3 to change the category");
System.out.println(" Press 4 to change the quantity");
System.out.println(" Press 5 to remove: ");
System.out.println("====================================================");
int choice=sc.nextInt();
if(choice==1)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new name: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update product set product_name='" + update + "' where product_id=" + product_id);
}
else if(choice==2)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new price: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update product set product_price='" + update + "' where product_id=" + product_id);
}
else if(choice==3)
{
rs=stmt.executeQuery("select category_id, category_name from categories");
while(rs.next()) {
System.out.println("Category ID: "+rs.getString("category_id")+" Category Name:"+rs.getString("category_name"));
}
System.out.println("------------------------------------------------");
System.out.println("Choose catgory: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update product set category_id='" + update + "' where product_id=" + product_id);
}
else if(choice==4)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new quantity: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update product set quantity='" + update + "' where product_id=" + product_id);
}
else if(choice==5)
{
System.out.println(" Deleted Product" );
System.out.println("------------------------------------------------");
stmt.executeUpdate("delete from products where product_id=" + product_id);
}
return 1;
}
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
public int edit_delieveryexecutive(Connection con)
{
try {
Statement stmt=con.createStatement();
try
{
System.out.println(" __________________________________________________");
System.out.println("|===================================================|");
System.out.println("| |");
System.out.println("| Delievery Executive Details |");
System.out.println("| |");
System.out.println("|===================================================|");
System.out.println("|1.View Delievery Executive |");
System.out.println("|2.Update or delete a Delievery Executive |");
System.out.println("|3.Exit |");
System.out.println(" __________________________________________________");
System.out.println(" Please enter your choice");
int flag=sc.nextInt();
if(flag==1) //View Product
{
System.out.println("*******************************************************************************************************");
System.out.println(" List of Delievery Executive" );
System.out.println("*******************************************************************************************************");
ResultSet rs=stmt.executeQuery("select * from delivery_executive" );
System.out.print("Delievery Executive ID " + "Delievery Executive Name "+ " Delievery Executive Number " + " Photo ID Type " +" Photo ID number " + "Rating");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("delivery_executive_id")+" "+rs.getString("delivery_executive_name")+" "+rs.getString("delivery_executive_phone")+" "+rs.getString("photo_id_type")+" "+rs.getString("photo_id_number")+" " + rs.getString("rating"));
}
System.out.println("*******************************************************************************************************");
return 1;
}
else if(flag==2) //Update and delete
{
System.out.println("**************************************************");
System.out.println(" Update and Delete");
System.out.println("**************************************************");
ResultSet rs=stmt.executeQuery("select * from delivery_executive" );
System.out.print("Delievery Executive ID " + "Delievery Executive Name "+ " Delievery Executive Number " + " Photo ID Type " +" Photo ID number " + "Rating");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("delivery_executive_id")+" "+rs.getString("delivery_executive_name")+" "+rs.getString("delivery_executive_phone")+" "+rs.getString("photo_id_type")+" "+rs.getString("photo_id_number")+" " + rs.getString("rating"));
}
System.out.println("Choose the ID of the executive you want to update/remove");
String delivery_executive_id=sc.next();
System.out.println("=========================================================================");
System.out.println(" Press 1 to change Delievery Executive name");
System.out.println(" Press 2 to change the Delievery Executive User ID");
System.out.println(" Press 3 to change the Delievery Executive password");
System.out.println(" Press 4 to change the Delievery Executive contact_number");
System.out.println(" Press 5 to change the Photo ID type code");
System.out.println(" Press 6 to change the Photo ID number rating");
System.out.println(" Press 7 to change the Photo ID number rating");
System.out.println(" Press 8 to remove: ");
System.out.println("=========================================================================");
int choice=sc.nextInt();
if(choice==1)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new name: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set delivery_executive_name='" + update + "' where delivery_executive_id=" + delivery_executive_id);
}
else if(choice==2)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new UserID: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set login_id='" + update + "' where delivery_executive_id=" + delivery_executive_id);
}
else if(choice==3)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new password: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set password='" + update + "' where delivery_executive_id=" + delivery_executive_id);
}
else if(choice==4)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new Contact Number: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set delivery_executive_phone='" + update + "' where delivery_executive_id=" + delivery_executive_id);
}
else if(choice==5)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter Photo Id Type: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set photo_id_type='" + update + "' where delivery_executive_id=" + delivery_executive_id);
}
else if(choice==6)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter Photo Id Number: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set photo_id_number='" + update + "' where delivery_executive_id=" + delivery_executive_id);
}
else if(choice==7)
{
System.out.println("------------------------------------------------");
System.out.println(" Enter new Rating: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set rating='" + update + "' where delivery_executive_id=" + delivery_executive_id);
}
else if(choice==8)
{
System.out.println(" Deleted Delievery Executive" );
System.out.println("------------------------------------------------");
stmt.executeUpdate("delete from delivery_executive where supplier_id=" + delivery_executive_id);
}
return 1;
}
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
public int edit_categories(Connection con)
{
try {
Statement stmt=con.createStatement();
try
{
System.out.println(" __________________________________________________");
System.out.println("|===================================================|");
System.out.println("| |");
System.out.println("| Categories Details |");
System.out.println("| |");
System.out.println("|===================================================|");
System.out.println("| 1.View Categories |");
System.out.println("| 2.Add Categories |");
System.out.println("| 3.Update or delete a Categories |");
System.out.println("| 4.Exit |");
System.out.println(" __________________________________________________");
System.out.println(" Please enter your choice");
int flag=sc.nextInt();
if(flag==1) //View Product
{
System.out.println("*******************************************************************************************************");
System.out.println(" List of Categories" );
System.out.println("*******************************************************************************************************");
ResultSet rs=stmt.executeQuery("select * from categories" );
System.out.print("CategoryID " + "Category Name ");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("category_id")+" "+rs.getString("category_name"));
}
return 1;
}
else if(flag==2) //Add new Product
{
System.out.println("**************************************************");
System.out.println(" Add new Category");
System.out.println("**************************************************");
System.out.println("------------------------------------------------");
System.out.println("Enter Name of the category:");
System.out.println("------------------------------------------------");
String category_name=sc.next();
try {
String query1="INSERT into categories (`category_name`)";
String query2="VALUES ('"+category_name+"')";
String final_query=query1+query2;
stmt.executeUpdate(final_query);
stmt.close();
return 1;
}
catch(Exception e) {
System.out.println(e);
}
stmt.close();
return 1;
}
else if(flag==3) //Update and delete
{
System.out.println("**************************************************");
System.out.println(" Update and Delete");
System.out.println("**************************************************");
ResultSet rs=stmt.executeQuery("select * from categories" );
System.out.print("CategoryID " + "Category Name ");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("category_id")+" "+rs.getString("category_name"));
}
System.out.println("Choose the Category ID of the category you want to update/remove");
String category_id=sc.next();
System.out.println("=========================================================================");
System.out.println(" Press 1 to change category name");
System.out.println(" Press 2 to remove: ");
System.out.println("=========================================================================");
int choice=sc.nextInt();
if(choice==1)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new name: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update categories set category_name='" + update + "' where category_id=" + category_id );
}
else if(choice==2)
{
System.out.println(" Deleted Category" );
System.out.println("------------------------------------------------");
stmt.executeUpdate("delete from categories where category_id=" + category_id);
}
return 1;
}
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
public int view_feedback(Connection con)
{
try {
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from feedback" );
System.out.print("Customer ID " + "Product ID " + "Supplier ID " + "Delievery Executive ID " + "Product Rating " + "Supplier Rating " + "Delievery Executive Rating " + "Submission date and time ");
while(rs.next()) {
System.out.println();
System.out.println(" " + rs.getString("customer_id")+" " +rs.getString("product_id")+" "+rs.getString("supplier_id")+" "+rs.getString("delivery_executive_id")+" "+rs.getString("product_rating")+" "+rs.getString("supplier_rating") +" "+rs.getString("delivery_executive_rating")+" "+rs.getString("submission_date"));
}
return 1;
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
public void edit_customer(Connection con)
{
try {
Statement stmt=con.createStatement();
try
{
System.out.println(" __________________________________________________");
System.out.println("|===================================================|");
System.out.println("| |");
System.out.println("| Consumer Details |");
System.out.println("| |");
System.out.println("|===================================================|");
System.out.println("|1.View consumer |");
System.out.println("|2.Update or delete a Consumer |");
System.out.println("|3.Exit |");
System.out.println(" __________________________________________________");
System.out.println(" Please enter your choice");
int flag=sc.nextInt();
if(flag==1) //View Product
{
System.out.println("*******************************************************************************************************");
System.out.println(" List of Consumers" );
System.out.println("*******************************************************************************************************");
ResultSet rs=stmt.executeQuery("select * from customer" );
System.out.print("ConsumerID " + "First Name " +"Last Name " + " Address Line 1 " + " Address Line 2 " + "City "+ "Pin Code " + "Contact Number " + "Country Code " +"Credit Limit Joined At ");
while(rs.next()) {
System.out.println();
System.out.println(" "+rs.getString("customer_id")+" "+rs.getString("first_name")+" "+rs.getString("last_name")+" "+rs.getString("address_line1")+" "+rs.getString("address_line2")+" "+rs.getString("city")+" "+rs.getString("pin_code")+" "+rs.getString("contact")+" "+rs.getString("country_code")+" "+rs.getString("credit_limit") +" "+ rs.getString("joined_at"));
}
System.out.println("*******************************************************************************************************");
// return 1;
}
else if(flag==2) //Update and delete
{
System.out.println("**************************************************");
System.out.println(" Update and Delete");
System.out.println("**************************************************");
ResultSet rs=stmt.executeQuery("select * from customer" );
System.out.print("ConsumerID " + "First Name " +"Last Name " + "Address Line 1 " + "Address Line 2 " + "City "+ "Pin Code " + "Contact Number " + "Country Code " +"Credit Limit Joined At ");
while(rs.next()) {
System.out.println();
System.out.println(rs.getString("customer_id")+rs.getString("first_name")+rs.getString("last_name")+rs.getString("address_line1")+rs.getString("address_line2")+rs.getString("city")+rs.getString("pin_code")+rs.getString("contact")+rs.getString("country_code")+rs.getString("credit_limit") + rs.getString("joined_at"));
}
System.out.println("Choose the Consumer ID of the customer you want to update/remove");
int customer_id=sc.nextInt();
System.out.println("====================================================");
System.out.println(" Press 1 to change Consumer name");
System.out.println(" Press 2 to change the Address");
System.out.println(" Press 3 to change the Consumer UserID");
System.out.println(" Press 4 to change the Password");
System.out.println(" Press 5 to change the Contact number");
System.out.println(" Press 6 to change the Credit Limit");
System.out.println(" Press 7 to remove: ");
System.out.println("====================================================");
int choice=sc.nextInt();
if(choice==1)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new First name: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update customer set first_name='"+ update + "' where customer_id=" + customer_id + ";");
System.out.println("------------------------------------------------");
System.out.println("Enter new Second name: ");
System.out.println("------------------------------------------------");
update=sc.next();
stmt.executeUpdate("Update customer set last_name='" + update + "' where customer_id=" + customer_id + ";");
}
else if(choice ==2)
{
System.out.println("------------------------------------------------");
System.out.println("Enter address line 1: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update customer set address_line1='" + update + "' where customer_id=" + customer_id);
System.out.println("------------------------------------------------");
System.out.println("Enter new address line 2: ");
System.out.println("------------------------------------------------");
update=sc.next();
stmt.executeUpdate("Update customer set address_line2='" + update + "' where customer_id=" + customer_id);
System.out.println("------------------------------------------------");
System.out.println("Enter city ");
System.out.println("------------------------------------------------");
update=sc.next();
stmt.executeUpdate("Update customer set city='" + update + "' where customer_id=" + customer_id);
System.out.println("------------------------------------------------");
System.out.println("Enter Pin Code ");
System.out.println("------------------------------------------------");
update=sc.next();
stmt.executeUpdate("Update customer set pin_code='" + update + "' where customer_id=" + customer_id);
}
else if(choice==4)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new password: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update customer set login_password='" + update + "' where customer_id=" + customer_id);
}
else if(choice==3)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new Second name: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update customer set login_id='" + update + "' where customer_id=" + customer_id);
}
else if(choice==5)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new Country code: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update customer set country_code='" + update + "' where customer_id=" + customer_id);
System.out.println("------------------------------------------------");
System.out.println("Enter new Contact Number: ");
System.out.println("------------------------------------------------");
update=sc.next();
stmt.executeUpdate("Update customer set contact='" + update + "' where customer_id=" + customer_id);
}
else if(choice==6)
{
System.out.println("------------------------------------------------");
System.out.println("Enter new Credit Limit: ");
System.out.println("------------------------------------------------");
String update=sc.next();
stmt.executeUpdate("Update customer set credit_limit='" + update + "' where customer_id=" + customer_id);
}
else if(choice==7)
{
System.out.println(" Deleted Consumer" );
System.out.println("------------------------------------------------");
stmt.executeUpdate("delete from customer where customer_id=" + customer_id);
}
}
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
}
}