Stock Levels

Reply

Join Date: Apr 2008
Posts: 11
Reputation: timon_zed is an unknown quantity at this point 
Solved Threads: 0
timon_zed timon_zed is offline Offline
Newbie Poster

Stock Levels

 
0
  #1
Sep 19th, 2009
Hello good citizens,
Am trying to implement a simple web based shopping system, however I want to find out if there is a way in which i can reduce the quantity of goods in stock after customer buys just by using servlets without me having to go to the database to change the stock levels.

Any feedback would be appreciated.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,245
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 492
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Stock Levels

 
-1
  #2
Sep 20th, 2009
In similar fashion as you query database to see what is available in stock you can link your customer purchase order action(on any website seen as button to "Confirm" after you provided delivery address and payment details) to a method in servlet to take data stored in order form to construct UPDATE query. Query will decrement you stock by certain amount, this would need to be done with sub-queries (query inside query) plus in same time you should also create new entry for new purchase order in different set of tables.
If you are more experienced with database you can even set up procedure for this sort of task.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 500
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Stock Levels

 
0
  #3
Sep 20th, 2009
Don't update or subtract values. Use aggregate sql functions.
For example,
1. Calculate the sum of quantity of a specific product in your purchase
table.
2. Calculate the sum of quantity of a specific product in your sales table.
3. Current stock = Sum of qty of purchase - Sum of qty of sales.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,245
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 492
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Stock Levels

 
-1
  #4
Sep 20th, 2009
Originally Posted by adatapost View Post
Don't update or subtract values. Use aggregate sql functions.
For example,
1. Calculate the sum of quantity of a specific product in your purchase
table.
2. Calculate the sum of quantity of a specific product in your sales table.
3. Current stock = Sum of qty of purchase - Sum of qty of sales.
Can you provide clearer explanation as I do understand that aggregate functions are
  • AVG() - Returns the average value
  • COUNT() - Returns the number of rows
  • FIRST() - Returns the first value
  • LAST() - Returns the last value
  • MAX() - Returns the largest value
  • MIN() - Returns the smallest value
  • SUM() - Returns the sum
and in my understanding these are used for calculation and not changing existing value in the table.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 500
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Stock Levels

 
0
  #5
Sep 20th, 2009
I apologize for inconvenience.
What I said,
Stock = Sum of quantity of purchased item - Sum of quantity of sold item.

EDIT: I suggest OP that don't update (add or subtract) total quantity.
Last edited by adatapost; Sep 20th, 2009 at 11:42 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 11
Reputation: timon_zed is an unknown quantity at this point 
Solved Threads: 0
timon_zed timon_zed is offline Offline
Newbie Poster

Re: Stock Levels

 
0
  #6
Sep 20th, 2009
Originally Posted by adatapost View Post
I apologize for inconvenience.
What I said,
Stock = Sum of quantity of purchased item - Sum of quantity of sold item.

EDIT: I suggest OP that don't update (add or subtract) total quantity.
I get the jist of what you're saying adatapost, so would this mean that i would have to add an update query within the same servlet that is processing the purchases made by customers?
I love to learn but I hate being taught - Winston Churchill
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 11
Reputation: timon_zed is an unknown quantity at this point 
Solved Threads: 0
timon_zed timon_zed is offline Offline
Newbie Poster

Re: Stock Levels

 
0
  #7
Sep 20th, 2009
Here's something i came up with....
  1. <form name="purchase" action="Purchase" method="POST">
  2. <table border="1">
  3. <thead>
  4. <tr>
  5. <th></th>
  6. <th></th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <tr>
  11. <td>Product Number</td>
  12. <td><input type="text" name="ProdNum" value="" maxlength="7" /></td>
  13. </tr>
  14. <tr>
  15. <td>Quantity</td>
  16. <td><input type="text" name="quantity" value="" /></td>
  17. </tr>
  18. <tr>
  19. <td><input type="reset" value="Clear" name="clear" /></td>
  20. <td><input type="submit" value="Purchase" name="purchase" /></td>
  21. </tr>
  22. </tbody>
  23. </table>
  24.  
  25. </form>
The associated servlet code sample...
  1. String ProdID = null;
  2. String ProdName = null;
  3. String Price1 = null;
  4. String Num = null;
  5. int cost,amt,value;
  6. try
  7. {
  8. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  9. Connection con = DriverManager.getConnection("jdbc:odbc:Concept","admin","");
  10. Statement st = con.createStatement();
  11. ResultSet rs = st.executeQuery ("SELECT ProductID, PName, Price FROM Stock");
  12.  
  13. while(rs.next())
  14. {
  15. ProdID = rs.getString("ProductID");
  16. if(ProdID.equals(request.getParameter("ProdNum")))
  17. {
  18. ProdName = rs.getString("PName");
  19. Price1 = rs.getString("Price");
  20. value = Integer.parseInt(Price1);
  21. Num = request.getParameter("quantity");
  22. amt = Integer.parseInt(Num);
  23. cost = amt*value;
  24. out.print(ProdID +'\t');
  25. out.print(ProdName + '\t');
  26. out.print(Num + '\t');
  27. out.print("K "+ cost);
  28. out.println('\t'+"<a href = purchase.jsp>Back</a>");
  29. }
  30. }
  31. con.close();
  32. rs.close ();
  33. st.close ();
  34. }
  35. catch(Exception e)
  36. {
  37. System.out.print("Unable to find DB");
  38. }
  39. }

What i need now is to find a way in which i can update the DB table by reducing the stocks of the purchased comodity just using this same servlet. Or do i need to write another servlet that would do that for me?
Reply With Quote Quick reply to this message  
Reply

Tags
levels, servlet, stocks

Message:


Thread Tools Search this Thread



Tag cloud for levels, servlet, stocks
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC