up
This commit is contained in:
30
.gitignore
vendored
Normal file
30
.gitignore
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
### IntelliJ IDEA ###
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
.kotlin
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
9
.idea/libraries/mysql_connector_j_9_6_0.xml
generated
Normal file
9
.idea/libraries/mysql_connector_j_9_6_0.xml
generated
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="mysql-connector-j-9.6.0">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-9.6.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/qlsp.iml" filepath="$PROJECT_DIR$/qlsp.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
BIN
lib/mysql-connector-j-9.6.0.jar
Normal file
BIN
lib/mysql-connector-j-9.6.0.jar
Normal file
Binary file not shown.
12
qlsp.iml
Normal file
12
qlsp.iml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="mysql-connector-j-9.6.0" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
8
src/Main.java
Normal file
8
src/Main.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import menus.ProductMgMenu;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ProductMgMenu productMgMenu = new ProductMgMenu();
|
||||||
|
productMgMenu.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/dao/ProductDAO.java
Normal file
44
src/dao/ProductDAO.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package dao;
|
||||||
|
|
||||||
|
import model.Product;
|
||||||
|
import utils.MysqlConnect;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ProductDAO {
|
||||||
|
|
||||||
|
public List<Product> getProductList() throws SQLException {
|
||||||
|
List<Product> result = new ArrayList<>();
|
||||||
|
|
||||||
|
String sql = "SELECT * FROM products";
|
||||||
|
|
||||||
|
Connection c = MysqlConnect.getConnecton();
|
||||||
|
|
||||||
|
PreparedStatement pt = c.prepareStatement(sql);
|
||||||
|
|
||||||
|
ResultSet rs = pt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
|
||||||
|
Product p = new Product(
|
||||||
|
rs.getInt("id"),
|
||||||
|
rs.getString("name"),
|
||||||
|
rs.getDouble("price"),
|
||||||
|
rs.getString("title"),
|
||||||
|
rs.getDate("created"),
|
||||||
|
rs.getString("catalog"),
|
||||||
|
rs.getBoolean("status")
|
||||||
|
);
|
||||||
|
|
||||||
|
result.add(p);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/db.sql
Normal file
12
src/db.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
create database product_management_db;
|
||||||
|
|
||||||
|
use database product_management_db;
|
||||||
|
|
||||||
|
CREATE TABLE `products` (
|
||||||
|
`id` int NOT NULL,
|
||||||
|
`name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||||
|
`price` float NOT NULL,
|
||||||
|
`title` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||||
|
`created` date NOT NULL,
|
||||||
|
`status` tinyint(1) NOT NULL DEFAULT '1'
|
||||||
|
);
|
||||||
41
src/menus/ProductMgMenu.java
Normal file
41
src/menus/ProductMgMenu.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package menus;
|
||||||
|
|
||||||
|
import services.ProductService;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class ProductMgMenu {
|
||||||
|
|
||||||
|
ProductService ps = new ProductService();
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
int choice;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
System.out.println("1/ Danh sách sản phẩm");
|
||||||
|
System.out.println("2/ Thêm mới sản phẩm");
|
||||||
|
System.out.println("3/ Cập nhật sản phẩm");
|
||||||
|
System.out.println("4/ Xóa sản phẩm");
|
||||||
|
System.out.println("5/ Tìm kiếm sản phẩm theo tên sản phẩm");
|
||||||
|
System.out.println("6/ Sắp xếp sản phẩm theo giá tăng dần");
|
||||||
|
System.out.println("7/ Thống kê số lượng sản phẩm theo danh mục");
|
||||||
|
System.out.println("0. Thoát");
|
||||||
|
|
||||||
|
System.out.println("Lựa chọn của bạn: ");
|
||||||
|
choice = sc.nextInt();
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
case 1:
|
||||||
|
ps.showProductList();
|
||||||
|
System.out.println("DSSP");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Lựa chọn kg phù hợp!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}while (choice != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
89
src/model/Product.java
Normal file
89
src/model/Product.java
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Product {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
Double price;
|
||||||
|
String title;
|
||||||
|
Date created;
|
||||||
|
String catalog;
|
||||||
|
Boolean status;
|
||||||
|
|
||||||
|
public Product(){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public Product(int id, String name, Double price, String title, Date created, String catalog, Boolean status) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.price = price;
|
||||||
|
this.title = title;
|
||||||
|
this.created = created;
|
||||||
|
this.catalog = catalog;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(Double price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreated(Date created) {
|
||||||
|
this.created = created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCatalog() {
|
||||||
|
return catalog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCatalog(String catalog) {
|
||||||
|
this.catalog = catalog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Boolean status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Tên SP " + this.name + " giá: " + this.price;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/services/ProductService.java
Normal file
16
src/services/ProductService.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package services;
|
||||||
|
|
||||||
|
import dao.ProductDAO;
|
||||||
|
|
||||||
|
public class ProductService {
|
||||||
|
ProductDAO productDAO = new ProductDAO();
|
||||||
|
|
||||||
|
public void showProductList() {
|
||||||
|
try {
|
||||||
|
System.out.println(productDAO.getProductList());
|
||||||
|
}catch (Exception e) {
|
||||||
|
System.out.println("Không thể đọc dữ liệu từ CSDL!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
src/utils/MysqlConnect.java
Normal file
18
src/utils/MysqlConnect.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package utils;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class MysqlConnect {
|
||||||
|
|
||||||
|
public static Connection getConnecton() {
|
||||||
|
try {
|
||||||
|
return DriverManager.getConnection("jdbc:mysql://localhost:3306/product_management_db?" + "user=root&password=");
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.out.println("loi " + ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user