Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Steve Green
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic