-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAllProduct.java
More file actions
48 lines (41 loc) · 1.39 KB
/
AllProduct.java
File metadata and controls
48 lines (41 loc) · 1.39 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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AllProduct {
Statement st;
private void connectToDb() {
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/productdb";
try {
Class.forName(driver);
Connection con=DriverManager.getConnection(url,"root","");
st=con.createStatement();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(AllProduct.class.getName()).log(Level.SEVERE, null, ex);
}
}
ArrayList viewItem() {
connectToDb();
String query="SELECT * FROM product";
List items=new ArrayList();
ResultSet rs;
try {
rs = st.executeQuery(query);
while(rs.next())
{
items.add(rs.getString("itmename"));
items.add(rs.getString("Price"));
items.add(rs.getString("description"));
}
} catch (SQLException ex) {
Logger.getLogger(AllProduct.class.getName()).log(Level.SEVERE, null, ex);
}
return (ArrayList) items;
}
}