-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolyCafe.java
More file actions
55 lines (49 loc) · 1.98 KB
/
PolyCafe.java
File metadata and controls
55 lines (49 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
package poly.cafe.polycafe;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import poly.cafe.entity.Category;
import poly.cafe.util.XJdbc;
import poly.cafe.util.XQuery;
public class PolyCafe {
public static void main(String[] args) {
try {
Connection conn = XJdbc.openConnection();
System.out.println("Kết nối thành công!");
conn.close();
} catch (SQLException e) {
System.out.println("Kết nối thất bại:");
e.printStackTrace();
}
// String insertSql = "INSERT INTO Categories (Id, Name) VALUES (?, ?)";
// XJdbc.executeUpdate(insertSql, "C07", "Loại 7");
// XJdbc.executeUpdate(insertSql, "C08", "Loại 8");
String selectSql = "SELECT * FROM Categories WHERE Name LIKE ?";
try (ResultSet rs = XJdbc.executeQuery(selectSql, "%Loại%")) {
System.out.println("\nTruy vấn ResultSet");
while (rs.next()) {
System.out.println(rs.getString("Id") + " " + rs.getString("Name"));
}
} catch (Exception e) {
e.printStackTrace();
}
// List<Category> list = XQuery.getBeanList(Category.class, selectSql, "%Loại%");
// System.out.println("\nDanh sách Category Bean");
// for (Category c : list) {
// System.out.println(c.getId() + " " + c.getName());
// }
//
// String oneSql = "SELECT * FROM Categories WHERE Id = ?";
// Category cat = XQuery.getSingleBean(Category.class, oneSql, "C02");
// System.out.println("\nMột Category");
// if (cat != null) {
// System.out.println(cat.getId() + " " + cat.getName());
// }
//
String maxIdSql = "SELECT MAX(Id) FROM Categories WHERE Name LIKE ?";
String maxId = (String) XJdbc.getValue(maxIdSql, "%Loại%");
System.out.println("\nMax ID: " + maxId);
}
}