Forums Register Login

help needed immediately

+Pie Number of slices to send: Send
Hi, i am writing a e-commerce program using jsp, servlet. There is a problem about inventory(stock). Please help me. i want to decrease the stock when customer check out, the problem how to make sure the database consistent, i mean there will be two customer check out(decrese the stock) at the same time. Is there any method to lock the table when one is checking out?
thanks in advance.
+Pie Number of slices to send: Send
Unfortunately I don't have enough experience to show you exactly how to do it, but look at Transactions. You can place the checkout method into a transaction. When it is done and everything is saved then you can commit it, otherwise you can rollback any changes.
JTA is the Transaction api. If you use EJBs it is even easier because the container can handle the transactions for you.
Mark
+Pie Number of slices to send: Send
Hi ordin,
I implemented mine using transactions in stored procedures.
Ex Animo Java!
-- Val
+Pie Number of slices to send: Send
Hi, Val Pecaoco
Could you send me your code? or please tell me more detail about how to do. thanks
e-mail: longf_76@yahoo.com
+Pie Number of slices to send: Send
You may want to synchronize the part of code involved in decreasing the stock and checking out.
+Pie Number of slices to send: Send
If your database and jdbc driver support transactions, then set AutoCommit to work and you will be using automatic transactions. There won't be a problem if you are simply doing two inserts simultaneously.
If you have more than one insert or update as part of the checkout process, autocommit won't be enough and you will have to turn it off and do the commit or rollback yourself on the connection object after the checkout.
HTH
Adam
+Pie Number of slices to send: Send
I think you need a way to Synchronize the users accessing the database. Why can't you use Threads (monitors - wait, notify) in the place where users access databse. By this way, only the user who has lock can access the database.
Thanks,
- Raja.
+Pie Number of slices to send: Send
The advantage of using database transactions rather than synchronizing the java code is that the transactions method has the additional advantage of being able to rollback both the checkout and the stock decrement if either of them fails, which means your data will stay clean in the event of a problem.
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 883 times.
Similar Threads
Using HashMaps HashLinkedLists and Maps
Chain Of Stores Code/Algorithm
only 1 of 2 method calls work in the same class
Big Smokes - Who cares about manufacturer stock levels?
DBTester and DBTestRunner in Max's book
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:02:58.