Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
62 changed files
with
1,452 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
-- MySQL dump 10.13 Distrib 8.0.22, for Win64 (x86_64) | ||
-- | ||
-- Host: localhost Database: ecommerce_cart | ||
-- ------------------------------------------------------ | ||
-- Server version 8.0.22 | ||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!50503 SET NAMES utf8 */; | ||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
|
||
-- | ||
-- Table structure for table `orders` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `orders`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!50503 SET character_set_client = utf8mb4 */; | ||
CREATE TABLE `orders` ( | ||
`o_id` int NOT NULL AUTO_INCREMENT, | ||
`p_id` int NOT NULL, | ||
`u_id` int NOT NULL, | ||
`o_quantity` int NOT NULL, | ||
`o_date` varchar(450) NOT NULL, | ||
PRIMARY KEY (`o_id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `orders` | ||
-- | ||
|
||
LOCK TABLES `orders` WRITE; | ||
/*!40000 ALTER TABLE `orders` DISABLE KEYS */; | ||
INSERT INTO `orders` VALUES (25,3,1,3,'2021-05-15'),(26,2,1,1,'2021-05-15'); | ||
/*!40000 ALTER TABLE `orders` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
|
||
-- | ||
-- Table structure for table `products` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `products`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!50503 SET character_set_client = utf8mb4 */; | ||
CREATE TABLE `products` ( | ||
`id` int NOT NULL AUTO_INCREMENT, | ||
`name` varchar(450) NOT NULL, | ||
`category` varchar(450) NOT NULL, | ||
`price` double NOT NULL, | ||
`image` varchar(450) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `products` | ||
-- | ||
|
||
LOCK TABLES `products` WRITE; | ||
/*!40000 ALTER TABLE `products` DISABLE KEYS */; | ||
INSERT INTO `products` VALUES (1,'New Arrival Femal Shoes','Female Shoes',120,'female-shoes.jpg'),(2,'Ladies Pure PU Shoulder Bag','Ladis Bag',69.99,'ladis-bag.jpg'),(3,'Stylish Men Office Suits','Men Clothes',169,'men-suits.jpg'),(4,'Jaeger-LeCoultre Men Watch','Men Watch',2500.99,'men-watch.jpg'),(5,'FreeMax e-cigarettes VB-456','E-Cigarattes',310,'smoking-e-cigarette.jpg'),(6,'GeekVapee e-cigarattes MM-632','E-Cigarattes',555.5,'smoking-e-cigarette-2.jpg'); | ||
/*!40000 ALTER TABLE `products` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
|
||
-- | ||
-- Table structure for table `users` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `users`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!50503 SET character_set_client = utf8mb4 */; | ||
CREATE TABLE `users` ( | ||
`id` int NOT NULL AUTO_INCREMENT, | ||
`name` varchar(250) NOT NULL, | ||
`email` varchar(250) NOT NULL, | ||
`password` varchar(250) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `email_UNIQUE` (`email`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `users` | ||
-- | ||
|
||
LOCK TABLES `users` WRITE; | ||
/*!40000 ALTER TABLE `users` DISABLE KEYS */; | ||
INSERT INTO `users` VALUES (1,'Almamun','almamun@mail.com','123456'); | ||
/*!40000 ALTER TABLE `users` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
|
||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
|
||
-- Dump completed on 2021-05-19 23:00:47 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>ecom-1</groupId> | ||
<artifactId>ecom</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.30</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<release>18</release> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.2.3</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package src.cn.techtutorial.connection; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
public class DbCon { | ||
private static Connection connection = null; | ||
public static Connection getConnection() throws ClassNotFoundException, SQLException{ | ||
if(connection == null){ | ||
Class.forName("com.mysql.cj.jdbc.Driver"); | ||
connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ecommerce_cart","root","root"); | ||
System.out.print("connected"); | ||
} | ||
return connection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package src.cn.techtutorial.dao; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.*; | ||
|
||
import src.cn.techtutorial.model.*; | ||
|
||
public class OrderDao { | ||
|
||
private Connection con; | ||
|
||
private String query; | ||
private PreparedStatement pst; | ||
private ResultSet rs; | ||
|
||
|
||
|
||
public OrderDao(Connection con) { | ||
super(); | ||
this.con = con; | ||
} | ||
|
||
public boolean insertOrder(Order model) { | ||
boolean result = false; | ||
try { | ||
query = "insert into orders (p_id, u_id, o_quantity, o_date) values(?,?,?,?)"; | ||
pst = this.con.prepareStatement(query); | ||
pst.setInt(1, model.getId()); | ||
pst.setInt(2, model.getUid()); | ||
pst.setInt(3, model.getQunatity()); | ||
pst.setString(4, model.getDate()); | ||
pst.executeUpdate(); | ||
result = true; | ||
} catch (SQLException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
return result; | ||
} | ||
|
||
|
||
public List<Order> userOrders(int id) { | ||
List<Order> list = new ArrayList<>(); | ||
try { | ||
query = "select * from orders where u_id=? order by orders.o_id desc"; | ||
pst = this.con.prepareStatement(query); | ||
pst.setInt(1, id); | ||
rs = pst.executeQuery(); | ||
while (rs.next()) { | ||
Order order = new Order(); | ||
ProductDao productDao = new ProductDao(this.con); | ||
int pId = rs.getInt("p_id"); | ||
Product product = productDao.getSingleProduct(pId); | ||
order.setOrderId(rs.getInt("o_id")); | ||
order.setId(pId); | ||
order.setName(product.getName()); | ||
order.setCategory(product.getCategory()); | ||
order.setPrice(product.getPrice()*rs.getInt("o_quantity")); | ||
order.setQunatity(rs.getInt("o_quantity")); | ||
order.setDate(rs.getString("o_date")); | ||
list.add(order); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.out.println(e.getMessage()); | ||
} | ||
return list; | ||
} | ||
|
||
public void cancelOrder(int id) { | ||
//boolean result = false; | ||
try { | ||
query = "delete from orders where o_id=?"; | ||
pst = this.con.prepareStatement(query); | ||
pst.setInt(1, id); | ||
pst.execute(); | ||
//result = true; | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
System.out.print(e.getMessage()); | ||
} | ||
//return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package src.cn.techtutorial.dao; | ||
|
||
import java.sql.*; | ||
import java.util.*; | ||
|
||
import src.cn.techtutorial.model.Cart; | ||
//import src.cn.techtutorial.model.Cart; | ||
import src.cn.techtutorial.model.Product; | ||
|
||
public class ProductDao { | ||
private Connection con; | ||
|
||
private String query; | ||
private PreparedStatement pst; | ||
private ResultSet rs; | ||
|
||
|
||
public ProductDao(Connection con) { | ||
super(); | ||
this.con = con; | ||
} | ||
|
||
|
||
public List<Product> getAllProducts() { | ||
List<Product> book = new ArrayList<>(); | ||
try { | ||
|
||
query = "select * from products"; | ||
pst = this.con.prepareStatement(query); | ||
rs = pst.executeQuery(); | ||
|
||
while (rs.next()) { | ||
Product row = new Product(); | ||
row.setId(rs.getInt("id")); | ||
row.setName(rs.getString("name")); | ||
row.setCategory(rs.getString("category")); | ||
row.setPrice(rs.getDouble("price")); | ||
row.setImage(rs.getString("image")); | ||
|
||
book.add(row); | ||
} | ||
|
||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
System.out.println(e.getMessage()); | ||
} | ||
return book; | ||
} | ||
|
||
|
||
public Product getSingleProduct(int id) { | ||
Product row = null; | ||
try { | ||
query = "select * from products where id=? "; | ||
|
||
pst = this.con.prepareStatement(query); | ||
pst.setInt(1, id); | ||
ResultSet rs = pst.executeQuery(); | ||
|
||
while (rs.next()) { | ||
row = new Product(); | ||
row.setId(rs.getInt("id")); | ||
row.setName(rs.getString("name")); | ||
row.setCategory(rs.getString("category")); | ||
row.setPrice(rs.getDouble("price")); | ||
row.setImage(rs.getString("image")); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.out.println(e.getMessage()); | ||
} | ||
|
||
return row; | ||
} | ||
|
||
public double getTotalCartPrice(ArrayList<Cart> cartList) { | ||
double sum = 0; | ||
try { | ||
if (cartList.size() > 0) { | ||
for (Cart item : cartList) { | ||
query = "select price from products where id=?"; | ||
pst = this.con.prepareStatement(query); | ||
pst.setInt(1, item.getId()); | ||
rs = pst.executeQuery(); | ||
while (rs.next()) { | ||
sum+=rs.getDouble("price")*item.getQuantity(); | ||
} | ||
|
||
} | ||
} | ||
|
||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
System.out.println(e.getMessage()); | ||
} | ||
return sum; | ||
} | ||
|
||
|
||
public List<Cart> getCartProducts(ArrayList<Cart> cartList) { | ||
List<Cart> book = new ArrayList<>(); | ||
try { | ||
if (cartList.size() > 0) { | ||
for (Cart item : cartList) { | ||
query = "select * from products where id=?"; | ||
pst = this.con.prepareStatement(query); | ||
pst.setInt(1, item.getId()); | ||
rs = pst.executeQuery(); | ||
while (rs.next()) { | ||
Cart row = new Cart(); | ||
row.setId(rs.getInt("id")); | ||
row.setName(rs.getString("name")); | ||
row.setCategory(rs.getString("category")); | ||
row.setPrice(rs.getDouble("price")*item.getQuantity()); | ||
row.setQuantity(item.getQuantity()); | ||
book.add(row); | ||
} | ||
|
||
} | ||
} | ||
|
||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
System.out.println(e.getMessage()); | ||
} | ||
return book; | ||
} | ||
} |
Oops, something went wrong.