FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java_Programs/InventoryManager.java at main · prittoruban/Java_Programs · GitHub
prittoruban
/
Java_Programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java_Programs
/
InventoryManager.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (66 loc) · 2.8 KB
Breadcrumbs
Java_Programs
/
InventoryManager.java
Copy path
File metadata and controls
72 lines (66 loc) · 2.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
sql
.*;
public
class
InventoryManager
{
private
Connection
connection
;
public
InventoryManager
() {
try
{
connection
=
DriverManager
.
getConnection
(
"jdbc:mysql://localhost:3306/your_database_name"
,
"your_username"
,
"your_password"
);
}
catch
(
SQLException
e
) {
System
.
out
.
println
(
e
.
getMessage
());
}
}
public
void
addProduct
(
String
name
,
String
category
,
int
quantity
) {
try
{
PreparedStatement
statement
=
connection
.
prepareStatement
(
"INSERT INTO inventory (name, category, quantity) VALUES (?, ?, ?)"
);
statement
.
setString
(
1
,
name
);
statement
.
setString
(
2
,
category
);
statement
.
setInt
(
3
,
quantity
);
statement
.
executeUpdate
();
}
catch
(
SQLException
e
) {
System
.
out
.
println
(
e
.
getMessage
());
}
}
public
void
updateProduct
(
String
name
,
String
category
,
int
quantity
) {
try
{
PreparedStatement
statement
=
connection
.
prepareStatement
(
"UPDATE inventory SET category = ?, quantity = ? WHERE name = ?"
);
statement
.
setString
(
1
,
category
);
statement
.
setInt
(
2
,
quantity
);
statement
.
setString
(
3
,
name
);
statement
.
executeUpdate
();
}
catch
(
SQLException
e
) {
System
.
out
.
println
(
e
.
getMessage
());
}
}
public
void
searchProductByName
(
String
name
) {
try
{
PreparedStatement
statement
=
connection
.
prepareStatement
(
"SELECT * FROM inventory WHERE name = ?"
);
statement
.
setString
(
1
,
name
);
ResultSet
resultSet
=
statement
.
executeQuery
();
while
(
resultSet
.
next
()) {
System
.
out
.
println
(
"Name: "
+
resultSet
.
getString
(
"name"
) +
", Category: "
+
resultSet
.
getString
(
"category"
) +
", Quantity: "
+
resultSet
.
getInt
(
"quantity"
));
}
}
catch
(
SQLException
e
) {
System
.
out
.
println
(
e
.
getMessage
());
}
}
public
void
searchProductByCategory
(
String
category
) {
try
{
PreparedStatement
statement
=
connection
.
prepareStatement
(
"SELECT * FROM inventory WHERE category = ?"
);
statement
.
setString
(
1
,
category
);
ResultSet
resultSet
=
statement
.
executeQuery
();
while
(
resultSet
.
next
()) {
System
.
out
.
println
(
"Name: "
+
resultSet
.
getString
(
"name"
) +
", Category: "
+
resultSet
.
getString
(
"category"
) +
", Quantity: "
+
resultSet
.
getInt
(
"quantity"
));
}
}
catch
(
SQLException
e
) {
System
.
out
.
println
(
e
.
getMessage
());
}
}
}
Back
|
FazBrowse Home
|
New Git URL