Skip to content
Permalink
a200e4a00e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
81 lines (66 sloc) 2.39 KB
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.ecommerce.dao;
import com.ecommerce.loginpack.model.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;
/**
*
* @author oladimeji
*/
public class OrderDao {
private Connection con;
private String query;
private PreparedStatement pst;
private ResultSet rs;
public OrderDao(Connection con){
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.getProductid());
pst.setInt(2, model.getUid());
pst.setInt(3, model.getQuantity());
pst.setString(4, model.getDate());
pst.executeUpdate();
result = true;
}
catch(Exception e){
e.printStackTrace();
}
return result;
}
public List<Order> userOrders(int id){
List<Order> list = new ArrayList<>();
try{
query = "select * from orders where u_id=? order by orders.orderid 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("orderid"));
order.setProductid(pId);
order.setName(product.getName());
order.setCategory(product.getCategory());
order.setPrice(product.getPrice()*rs.getInt("o_quantity"));
order.setQuantity(rs.getInt("o_quantity"));
order.setDate(rs.getString("o_date"));
list.add(order);
}
}catch(Exception e){
e.printStackTrace();
}
return list;
}
}