<%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.*" %> <%@ page import="java.text.*" %> <% String cart=null; cart=(String) session.getAttribute("cart"); //out.print("Cart : "+cart); if (cart==null || cart.equals(null)) { //out.print("A"); String filepath; filepath = application.getRealPath("/"); FileReader fr = new FileReader(filepath + "file2.txt"); BufferedReader br = new BufferedReader(fr); String s; String str = ""; int intsource=0; while((s=br.readLine()) != null ) { str=s; } intsource = Integer.parseInt(str); intsource +=1; String source =""; source = String.valueOf(intsource); java.io.FileWriter f1 = new java.io.FileWriter(filepath + "file2.txt"); f1.write(source); //out.println("Session:" + source); f1.close(); session.setAttribute("cart",source); } %> <% int intuid=0; //String insertstr ="INSERT INTO recipelandingpage (id,title,desc1,img,approved) values(?,?,?,?,?)"; Connection dbCon = null; PreparedStatement stataddcart = null; PreparedStatement statprod = null; PreparedStatement statmax = null; PreparedStatement stat = null; PreparedStatement statdel = null; PreparedStatement statchk = null; PreparedStatement stat1 = null; PreparedStatement statupdate = null; String prodstr="select * from vendorproduct where id=?"; String addcartstr="insert into shoppingcart(id,sessionid,prodid,qty,price,prodname) values(?,?,?,?,?,?)"; String maxstr = "Select max(id) as maxid from shoppingcart"; String selectstr = "Select * from shoppingcart where sessionid=?"; String deletestr = "delete from shoppingcart where id=?"; String chkstr = "Select * from shoppingcart where sessionid=? and prodid=?"; String str1="select * from shoppingcart where sessionid=?"; String updatestr="update shoppingcart set qty =? where id=?"; ResultSet rsaddcart = null; ResultSet rsprod = null; ResultSet rsmax = null; ResultSet rs = null; ResultSet rsdel = null; ResultSet rschk = null; ResultSet rs1 = null; ResultSet rsupdate = null; try { //out.println("Approved :" + approved); //javax.naming.Context initialContext = new javax.naming.InitialContext(); //javax.naming.Context envContext = (javax.naming.Context) initialContext.lookup("java:/comp/env"); //javax.sql.DataSource dataSource = (javax.sql.DataSource) envContext.lookup("jdbc/mssql"); //dbCon = dataSource.getConnection(); Class.forName("com.mysql.jdbc.Driver").newInstance(); //dbCon = DriverManager.getConnection("jdbc:mysql://localhost:3306/maheks_mahek","maheks","mahak"); //dbCon = DriverManager.getConnection("jdbc:mysql://localhost:3306/myrecipe","root",""); ServletContext ctx = getServletContext(); String url=ctx.getInitParameter("url"); String user=ctx.getInitParameter("user"); String pw=ctx.getInitParameter("password"); dbCon = DriverManager.getConnection(url,user,pw); //out.print("Cart : "+cart); int sessionid=Integer.parseInt(cart); String loginmsg = request.getParameter("msg"); String update = request.getParameter("update"); String updstr=null; int counter=0; if (update!=null) { counter=Integer.parseInt(request.getParameter("counter")); stat1=dbCon.prepareStatement(str1); stat1.setInt(1,sessionid); rs1=stat1.executeQuery(); String qty=null; statupdate=dbCon.prepareStatement(updatestr); while (rs1.next()) { updstr="Product updated successfully!"; qty=request.getParameter("qty"+rs1.getInt("id")); statupdate.setString(1,qty); statupdate.setInt(2,rs1.getInt("id")); statupdate.executeUpdate(); //out.print(request.getParameter("qty"+rs1.getInt("id"))); } //int iddel=Integer.parseInt(request.getParameter("id")); // statdel=dbCon.prepareStatement(deletestr); // statdel.setInt(1,iddel); // statdel.executeUpdate(); } String del = request.getParameter("del"); String delstr=null; if (del!=null) { delstr="Product deleted successfully!"; int iddel=Integer.parseInt(request.getParameter("id")); statdel=dbCon.prepareStatement(deletestr); statdel.setInt(1,iddel); statdel.executeUpdate(); } String chkmsg=null; String add = request.getParameter("add"); int prodid=0; int cartid=0; if (add!=null) { //Integer sessionid = (Integer) session.getAttribute("cart"); prodid=Integer.parseInt(request.getParameter("id")); statchk=dbCon.prepareStatement(chkstr); statchk.setInt(1,sessionid); statchk.setInt(2,prodid); rschk=statchk.executeQuery(); if (rschk.next()) { chkmsg ="Product you have selected is already present in your cart."; } else { //out.print("1"); statprod=dbCon.prepareStatement(prodstr); statprod.setInt(1,prodid); rsprod=statprod.executeQuery(); statmax=dbCon.prepareStatement(maxstr); rsmax=statmax.executeQuery(); stataddcart=dbCon.prepareStatement(addcartstr); String title=null; String price=null; if (rsprod.next()) { title=rsprod.getString("prodtitle"); price=rsprod.getString("costprice"); } if(rsmax.next()) { cartid = rsmax.getInt("maxid"); //out.println(intuid); cartid+=1; } else { cartid = 1; } //id,sessionid,prodid,qty,price stataddcart.setInt(1,cartid); stataddcart.setInt(2,sessionid); stataddcart.setInt(3,prodid); stataddcart.setString(4,"1"); stataddcart.setString(5,price); stataddcart.setString(6,title); stataddcart.executeUpdate(); } } stat=dbCon.prepareStatement(selectstr); stat.setInt(1,sessionid); rs=stat.executeQuery(); %> Mahek's Cooking Classes
 
 
Shopping cart » Browse  

 

 
 
 
Your Shopping Cart
 
<% int prc=0; int amt=0; int q=0; int gtotal=0; int ii=0; String qtystr=null; while (rs.next()) { ii=ii+1; prc=Integer.parseInt(rs.getString("price")); q=Integer.parseInt(rs.getString("qty")); amt=prc*q; gtotal=gtotal+amt; qtystr="qty"+rs.getInt("id"); %> <% } %>
Item Name
Qty
Price
Total
Action
<%=rs.getString("prodname")%>
" size="3">
Rs. <%=rs.getString("price")%>
Rs. <%=amt%>
" onClick="return confirm('Are you sure you want to delete this item?')">Delete  
Grand total : Rs. <%=gtotal%>
<% if (chkmsg!=null) { out.print(chkmsg); } %> <% if (updstr!=null) { out.print(updstr); } %> <% if (delstr!=null) { out.print(delstr); } %> <% if (loginmsg!=null) { out.print(loginmsg); } %> <% String reg=request.getParameter("reg"); if (reg!=null) { %> Dear <%=session.getAttribute("userid")%>, You are now registered with Makeks.com.
Confirmation mail has been send to your email id. <% } %>
 
 
 
 
 
Send gift items to India . All major credit cards accepted.
Free shipping all over india, normally
 
 
© 2001-2007 Mahek’s Cooking Classes. | Web design by livepages  
<% } catch (java.sql.SQLException e2) { out.println(e2.toString()); } catch (java.lang.NumberFormatException e3) { out.println(e3.toString()); e3.printStackTrace(new java.io.PrintWriter(out)); } catch (Exception e) { out.println("

ERROR!

"); out.println("Error = " + e.getMessage() + "
");
  			e.printStackTrace(new java.io.PrintWriter(out));
  			out.println("
"); return; } finally { try { if(dbCon != null) dbCon.close(); } catch(SQLException sqle) {} } %>