-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAdmin.java
More file actions
140 lines (133 loc) · 5.45 KB
/
Copy pathAdmin.java
File metadata and controls
140 lines (133 loc) · 5.45 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
import java.util.Scanner;
import java.sql.*;
public class Admin {
int pid, Qty, orderno = 9001, update;
int price = 0, Tot_Price = 0;
String s, name;
Scanner sc = new Scanner(System.in);
Connection con = null;
Statement stmt = null;
PreparedStatement ps = null;
ResultSet rs;
Admin() {
try {
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/db?characterEncoding=latin1&useConfigs=maxPerformance", "scott",
"tiger");
stmt = con.createStatement();
// step1 load the driver class
Class.forName("com.mysql.jdbc.Driver");
// step2 create the connection object
} catch (Exception e) {
System.out.println(e);
}
// step3 create the statement object
}
public void Add_Product() {
System.out.println("Enter the product details:\nProduct name: ");
name = sc.nextLine();
System.out.println("Product id: ");
pid = sc.nextInt();
System.out.println("Price: ");
price = sc.nextInt();
System.out.println("Quantity: ");
Qty = sc.nextInt();
s = "insert into stockings values(" + pid + ",'" + name + "'," + price + "," + Qty
+ ")";
try {
ps = con.prepareStatement(s);
ps.execute();
} catch (Exception e) {
System.out.println(e);
}
}
public void Update_Inventory() {
try {
System.out.println("Product list:\n");
s = "select pid, product, price, qty FROM Stockings";
rs = stmt.executeQuery(s);
System.out.println("Pid\tProduct name\tPrice\tQuantity\n----------------------------------------");
while (rs.next())
System.out.println(rs.getInt(1)+"\t"+rs.getString(2) + "\t" + rs.getInt(3)
+ "\t" + rs.getInt(4));
System.out.println("Enter the id of the product to be updated: ");
pid = sc.nextInt();
System.out.println("Quantity: ");
Qty = sc.nextInt();
s = "update stockings set qty = " + Qty + " WHERE pid = " + pid;
ps = con.prepareStatement(s);
ps.execute();
} catch (Exception e) {
System.out.println(e);
}
}
public void Change_Price() {
try {
System.out.println("Product list:\n");
s = "select pid, product, price, qty FROM Stockings";
rs = stmt.executeQuery(s);
System.out.println("Pid\tProduct name\tPrice\tQuantity\n----------------------------------------");
while (rs.next())
System.out.println(rs.getInt(1)+"\t"+rs.getString(2) + "\t" +
rs.getInt(3) + "\t" + rs.getInt(4));
System.out.println("Enter the id of the product on sale: ");
pid = sc.nextInt();
System.out.println("Enter Discount: ");
float disc = sc.nextInt();
s = "select price from Stockings where pid = " + pid;
rs = stmt.executeQuery(s);
rs.next();
price = rs.getInt(1);
price -= price * (disc / 100);
System.out.println("New price: ");
s = "update stockings set price = " + price + " WHERE pid = " + pid;
ps = con.prepareStatement(s);
ps.execute();
} catch (Exception e) {
System.out.println(e);
}
}
public void Delete_Product() {
try {
System.out.println("Product list:\n");
s = "select pid, product, price, qty FROM Stockings";
rs = stmt.executeQuery(s);
System.out.println("Pid\tProduct name\tPrice\tQuantity\n----------------------------------------");
while (rs.next())
System.out.println(rs.getInt(1)+"\t"+rs.getString(2) + "\t" +
rs.getInt(3) + "\t" + rs.getInt(4));
System.out.println("Enter product id to be deleted: ");
pid = sc.nextInt();
System.out.println("Product deleted!");
s = "delete from stockings where pid = " + pid;
ps = con.prepareStatement(s);
ps.execute();
}
catch (Exception e) {
System.out.println(e);
}
}
public void View_Orders() {
try {
System.out.println("Product list:\n");
s = "select pid, product, price, qty FROM Stockings";
rs = stmt.executeQuery(s);
System.out.println("Pid\tProduct name\tPrice\tQuantity\n----------------------------------------");
while (rs.next())
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3)+"\t"
+ rs.getInt(4));
System.out.println("Enter the id of the product: ");
pid = sc.nextInt();
System.out.println("\nOrderID\tQty\tCustomer ID\n--------------------------");
s = "select oid,o.qty,custid from stockings s, orders o WHERE s.pid = o.prodid AND s.pid = "
+ pid;
rs = stmt.executeQuery(s);
while (rs.next())
System.out.println(rs.getInt(1)+"\t"+rs.getInt(2)+"\t"+rs.getInt(3));
// SELECT OrderID, Qty AS Quantity Ordered FROM Stocking s, Orders o WHERE
// s.ProductID == o.pid AND s.ProductID == pid AND Date_Of_Closing >= SYSDATE;
} catch (Exception e) {
System.out.println(e);
}
}
}