Repository navigation
Expand file tree
/
Copy pathProductTable.java
More file actions
91 lines (81 loc) · 1.98 KB
/
Copy pathProductTable.java
File metadata and controls
91 lines (81 loc) · 1.98 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
package TugasKuis;
import java.util.List;
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 javax.swing.JOptionPane;
public class ProductTable {
Connection connection;
public ProductTable()
{
try{
Class.forName(config.DATABASE_DRIVER).newInstance();
connection = DriverManager.getConnection(config.URL, config.USERNAME, config.PASSWORD);
}catch (Exception e)
{
}
}
public Product cariById(String id)
{
Product pHasil = null;
try{
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from products where ID = '"+ id +"'");
while (rs.next())
{
String nama = rs.getString(2);
String idSupplier = rs.getString(3);
int harga = rs.getInt(4);
pHasil = new Product (id, nama, idSupplier, harga);
}
}catch (SQLException e)
{
e.printStackTrace();
}
return pHasil;
}
public List<Product> viewAll()
{
List <Product> daftarProduct = new ArrayList<Product>();
try
{
//rs=selectAll.executeQuery();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from products");
while(rs.next())
{
//daftarProduct.add(new Product(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4)));
}
} catch (SQLException e)
{
e.printStackTrace();
}
return daftarProduct;
}
public List<Product> viewAll(String filter)
{
return null;
}
public void insert(Product produk)
{
}
public void delete(String id)
{
}
public void update(String id,Product prodUpdated)
{
}
/*public static void main (String []args) throws Exception
{
String id = JOptionPane.showInputDialog("Masukkan ID Product : ");
ProductTable pt = new ProductTable();
Product p1 = pt.cariById(id);
System.out.println(p1);
//List <Product> hasilAll = pt.viewAll();
//for(Product p:hasilAll);
//System.out.ptrintln(p);
}*/
}