| | |
Stock Levels
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 11
Reputation:
Solved Threads: 0
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.
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.
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.
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
•
•
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.
- 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
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Apr 2008
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
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 love to learn but I hate being taught - Winston Churchill
•
•
Join Date: Apr 2008
Posts: 11
Reputation:
Solved Threads: 0
Here's something i came up with....
The associated servlet code sample...
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?
JSP Syntax (Toggle Plain Text)
<form name="purchase" action="Purchase" method="POST"> <table border="1"> <thead> <tr> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td>Product Number</td> <td><input type="text" name="ProdNum" value="" maxlength="7" /></td> </tr> <tr> <td>Quantity</td> <td><input type="text" name="quantity" value="" /></td> </tr> <tr> <td><input type="reset" value="Clear" name="clear" /></td> <td><input type="submit" value="Purchase" name="purchase" /></td> </tr> </tbody> </table> </form>
JSP Syntax (Toggle Plain Text)
String ProdID = null; String ProdName = null; String Price1 = null; String Num = null; int cost,amt,value; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Concept","admin",""); Statement st = con.createStatement(); ResultSet rs = st.executeQuery ("SELECT ProductID, PName, Price FROM Stock"); while(rs.next()) { ProdID = rs.getString("ProductID"); if(ProdID.equals(request.getParameter("ProdNum"))) { ProdName = rs.getString("PName"); Price1 = rs.getString("Price"); value = Integer.parseInt(Price1); Num = request.getParameter("quantity"); amt = Integer.parseInt(Num); cost = amt*value; out.print(ProdID +'\t'); out.print(ProdName + '\t'); out.print(Num + '\t'); out.print("K "+ cost); out.println('\t'+"<a href = purchase.jsp>Back</a>"); } } con.close(); rs.close (); st.close (); } catch(Exception e) { System.out.print("Unable to find DB"); } }
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?
![]() |
Similar Threads
- Need suggestion on Inventory System database design (Database Design)
- Restarting Application (C++)
- News Story: Apple Stock Suffering From PR Debacle (Apple Hardware)
- Iinformation systems case study entities and events?? (Computer Science)
- final year project advice (Oracle)
- final year project advice (Database Design)
- From * Where =< in Access Database (ASP)
- case study help please (Networking Hardware Configuration)
- project help (Visual Basic 4 / 5 / 6)
Other Threads in the JSP Forum
- Previous Thread: Adding a submit button to each row generated
- Next Thread: Prb with jsp and how to delete multiple rows
| Thread Tools | Search this Thread |
Tag cloud for levels, servlet, stocks
2008 apple bailout bankdeposits banks biometrics biotech blackberry broadband bush cell china chips christmas cisco connection consumerconfidence corporateearnings credit database debtcollectors dot.com economy email employment fidelity fingerprints fuel.energy funds gamestop gartnergroup gdp grandtheftauto hand handhelds hdtv holidayshopping homesales housing hp idc intel internet investing investment investments investors java jsp lehman levels loans madden markets merger microndevices microprocessors microsoft money motorola mvc2 mvcmodel2 nasdaq nintendo oil online phones portfolio recession retail routers samsung sap semiconductors servlet sony sprint stockbuybacks stocks subprime tech technology technologycompanies telecom television tutorial verizon videogame videogames web yahoo







