File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Help with both Inserting tables and using a servet to run the queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help with both Inserting tables and using a servet to run the queries" Watch "Help with both Inserting tables and using a servet to run the queries" New topic
Author

Help with both Inserting tables and using a servet to run the queries

Steve Green
Greenhorn

Joined: Dec 07, 2011
Posts: 4
Hi guys,

I'm hoping someone may be able to help with Servlets and Sql as well as some bits in general

I've a task that involves creating a website that imitates an online shop.

Theres a database involved with relevant info for obtaining the details.

So far, I've got the site up and running using both html pages and servlets. I can run queries to the db using the servlet and postgres and can also display the info on another screen.

What I'd like to do is firstly find out the correct method for inserting the information gathered such as card details etc into the db and also how I can use this to reflect stock levels? I'm thinking that as soon as something is bought I must have to 'delete' that item from the stock while inserting the item and card details etc into 2 new tables (payments and cust info)

Could anyone help please?

Also...I'm searching for a way to validate the information given. I'd like to restrict the text field for contact numbers to nothing but numbers. And also for the card lenght, must be 16 digits etc.

For card length I cna see the logic fairly clearly in that : if (cardLength > 16){print error etc}else{return} (I think this is structured incorrectly but I hope the logic is partially right.

Many thanks for your time and help!

Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90


Steve Green wrote:
What I'd like to do is firstly find out the correct method for inserting the information gathered such as card details etc into the db and also how I can use this to reflect stock levels? I'm thinking that as soon as something is bought I must have to 'delete' that item from the stock while inserting the item and card details etc into 2 new tables (payments and cust info)


Hi Steve,
Inserting information pretty much depends on the way you designed your database.

It has to be two or three different queries for inserting info into appropriate tables. Lets say you have a sales table that takes the information of each sales bill and and sales_item table that takes the information about the items sold in that particular sales bill. And then you have another table that describes independently each item that you have in your inventory and their quantity.
So if you try to make entries for a particular sales, you need to update the sales table with all information, and a sales_item table with the items bought and also the inventory where you need to reduce the quantity of the items sold.
So it would be multiple queries for one sales.

But the thing you need to take care of is that the whole process should be atomic i.e either all of it happens or nothing happens. So you need to use a database transaction for it.
Check out this link to learn a little about database transactions. The example provided there is similar to your case.

http://www.devx.com/tips/Tip/15015

And your way for checking validation looks okay to me.

This is the first time I am replying to someone's query. So research well before you implement the code. I hope I atleast provided a direction.

All the best


 
wood burning stoves
 
subject: Help with both Inserting tables and using a servet to run the queries