wood burning stoves 2.0*
The moose likes Servlets and the fly likes Storing form data in a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Storing form data in a database" Watch "Storing form data in a database" New topic
Author

Storing form data in a database

swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
Hey,
I've a HTML form say,Feedback.html.I need to retrieve values from it and store it in the database table.I ve got FeedbackServlet.java which shd be doing this.I am storing the values in the vector.
But the problem is,The order of columns changes for every Submit.So i can not store as is it in a table.What do i do??and How??
Shd I ve a 2 dimensional vector and get column names & values dynamically??(i tried this but failed)
Can nayone help me with this or suggest smthg better
Thanxx
SWati


Swati Kale
SCJP
SCWCD
P SOLAIAPPAN
Ranch Hand

Joined: Oct 20, 2000
Posts: 68
Hi,
I donot understand what is
"The order of columns changes for every Submit."
If you give some more details with code, may I may able to help.
solaiappan
ram kumar
Greenhorn

Joined: Nov 24, 2000
Posts: 12
hi swati
its pretty simple don't go for vector..since the fields in the feedback form is defined(say 10 fields)..go for an array then store values from the field seperated by a delimiter | sign.you can use a string tokenizer to retrieve the values and store it in database and also you can store the values as per you sorting which will not give you the problem as you mentioned earlier in vector
all the best
ram
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
Originally posted by P SOLAIAPPAN:
Hi,
I donot understand what is
"The order of columns changes for every Submit."
If you give some more details with code, may I may able to help.
solaiappan

Hello, What I mean by this is..
Say ,I ve 9 fields in my form and have corresponding database columns in my Table Feedback_Master_T.Feedbackform has fields namely Username,Email,Fax,TEl,Comments etc.So when user clicks on submit ,the order in which the values shd get insert into the table is Username,email,Fax,Tel,Comments.
But this order is getting changed for EVERY SUBMit and so I am having problem inserting it into the database.In mytable I get name in Fax column and so on.
Is it clear now??
So I need to retrieve field names & values dynamically and accordingly write the insert statement
Will u be bale to help me now??
Thanx
Swati

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It is always good procedure to use the full form (with column names) of a SQL insert statement, so that which columns you are inserting are tied to the values. It is also good practice to extract servlet parameters by name too, so you should be able to avaoid this problem.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
Originally posted by Frank Carver:
It is always good procedure to use the full form (with column names) of a SQL insert statement, so that which columns you are inserting are tied to the values. It is also good practice to extract servlet parameters by name too, so you should be able to avaoid this problem.

Thankx
It did work properly.All my problems are solved
Swati
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing form data in a database