You are on page 1of 3

package com.

controller;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.ArrayList;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.servlet.ModelAndView;

import com.model.OrderModel;

import com.utils.DatabaseConnection;

@Controller

public class OrderController {

@RequestMapping(value="/orders",method = RequestMethod.GET)

public ModelAndView order(HttpSession sess) {

if(sess.getAttribute("user") == null)

return new ModelAndView("index","message","Please Login!!");

Connection con1 = DatabaseConnection.getConnection();

PreparedStatement pre = null;

ResultSet rs = null;

List<OrderModel> listofUser= new ArrayList<>();

String query = "select


o.Order_id,o.product_id,o.email_id,o.bought_by,o.Payment_mode,o.payment_status,o.order_date,
o.delivery_date,o.delivery_status,p.product_sub,p.product_name,p.product_price,p.product_img
from orders as o,products as p,registration as r where p.product_id=o.product_id and o.email_id =
r.Email_id and o.email_id = ? ";

try {

pre = con1.prepareStatement(query);
pre.setString(1, sess.getAttribute("id").toString());

rs= pre.executeQuery();

while(rs.next()){

OrderModel proModel = new OrderModel();

proModel.setOrder_id(rs.getInt("Order_id"));

proModel.setProduct_id(rs.getInt("product_id"));

proModel.setEmail_id(rs.getString("email_id"));

proModel.setBought_by(rs.getString("bought_by"));

proModel.setPayment_mode(rs.getString("Payment_mode"));

proModel.setPayment_status(rs.getString("payment_status"));

proModel.setOrder_date(rs.getString("order_date"));

proModel.setDelivery_date(rs.getString("delivery_date"));

proModel.setDelivery_status(rs.getString("delivery_status"));

proModel.setProduct_sub(rs.getString("product_sub"));

proModel.setProduct_name(rs.getString("product_img"));

proModel.setProduct_price(rs.getDouble("product_price"));

proModel.setProduct_img(rs.getString("product_img"));

listofUser.add(proModel);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

pre.close();

con1.close();

} catch (Exception e) {

e.printStackTrace();

}
if(listofUser.isEmpty())

return new ModelAndView("Orders","err","No Items available!!");

else

return new ModelAndView("Orders","listofUser",listofUser);

You might also like