Guest User

Untitled

a guest
Mar 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public static ArrayList<products> selectcart(String uname)
  2. {
  3. ArrayList<products> ap=ap=new ArrayList<>();
  4. products p=null;
  5.  
  6. ps=null;
  7. rs=null;
  8.  
  9. stmnt="select PID,P_QTY,P_SIZE from cart where uname=?";
  10. try {
  11. ps=con.prepareStatement(stmnt);
  12. ps.setString(1, uname);
  13. rs=ps.executeQuery();
  14.  
  15. if(rs!=null)
  16. {
  17. int cou=0;
  18. while(rs.next())
  19. {
  20. p=new products();
  21. p.setPid(rs.getInt(1));
  22. p.setP_quantity(rs.getInt(2));
  23. p.setP_size(rs.getInt(3));
  24. p=selectproduct(p);
  25. ap.add(p);
  26. p=null;
  27. System.out.println(cou++);
  28. }
  29. System.out.println(ap);
  30. }
  31. } catch (SQLException e) {
  32. // TODO Auto-generated catch block
  33. e.printStackTrace();
  34. }
  35. return ap;
  36. }
  37.  
  38. private static products selectproduct(products p)
  39. {
  40.  
  41. ps=null;
  42. rs=null;
  43. stmnt="select p_name,p_image,p_price from Products where pid=?";
  44. try
  45. {
  46. ps=con.prepareStatement(stmnt);
  47. ps.setInt(1,p.getPid());
  48. rs=ps.executeQuery();
  49. if(rs!=null)
  50. {
  51. while(rs.next())
  52. {
  53. p.setName(rs.getString(1));
  54. p.setP_image(rs.getBlob(2));
  55. p.setP_price(rs.getDouble(3));
  56. }
  57. }
  58. }
  59. catch(Exception e)
  60. {
  61. e.printStackTrace();
  62. }
  63. return p;
  64. }
Add Comment
Please, Sign In to add comment