943,648 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 1592
  • JSP RSS
Sep 19th, 2009
0

Stock Levels

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
timon_zed is offline Offline
13 posts
since Apr 2008
Sep 20th, 2009
-1

Re: Stock Levels

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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Sep 20th, 2009
0

Re: Stock Levels

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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 20th, 2009
-1

Re: Stock Levels

Click to Expand / Collapse  Quote originally posted by adatapost ...
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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Sep 20th, 2009
0

Re: Stock Levels

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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 20th, 2009
0

Re: Stock Levels

Click to Expand / Collapse  Quote originally posted by adatapost ...
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?
Quote ...
I love to learn but I hate being taught - Winston Churchill
Reputation Points: 10
Solved Threads: 0
Newbie Poster
timon_zed is offline Offline
13 posts
since Apr 2008
Sep 20th, 2009
0

Re: Stock Levels

Here's something i came up with....
JSP Syntax (Toggle Plain Text)
  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...
JSP Syntax (Toggle Plain Text)
  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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
timon_zed is offline Offline
13 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Adding a submit button to each row generated
Next Thread in JSP Forum Timeline: Prb with jsp and how to delete multiple rows





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC