-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductProcess.java
More file actions
31 lines (29 loc) · 1.11 KB
/
Copy pathProductProcess.java
File metadata and controls
31 lines (29 loc) · 1.11 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
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class ProductProcess {
public List<Product> getAllProducts() {
List<Product> products = new ArrayList<>();
Connection conn = null;
DBConnection helper = new DBConnection();
Statement statement = null;
ResultSet resultSet = null;
try{
conn = helper.getConnection();
statement = conn.createStatement();
resultSet = statement.executeQuery("SELECT * FROM products");
while(resultSet.next()){
products.add(new Product(
resultSet.getInt("productID"),
resultSet.getString("productName"),
resultSet.getString("productDescription"),
resultSet.getDouble("productPrice"),
resultSet.getInt("productStockQuantity")));
}
System.out.println("Connected to database");
} catch (SQLException e) {
e.printStackTrace();
}
return products;
}
}