| Author |
storing checkbox data inside database
|
Ravi Kiran Va
Ranch Hand
Joined: Apr 18, 2009
Posts: 2234
|
|
Hi Ranchers ,
I have a JSP Page UI Page (The Form Page) .
This consists of User Data like Name , Age ----etc . This also consists of his personnel interests like Cricket , FootBall , BaseBall which are to be
ticked in checkbox .
<input type="checkbox" name="option" value="Milk"> Cricket<br>
<input type="checkbox" name="option" value="Butter" > FootBall<br>
<input type="checkbox" name="option" value="Cheese"> BaseBall<br>
Please tell me how can store his interests in Database??
|
Save India From Corruption - Anna Hazare.
|
 |
Krishnan Iyer
Greenhorn
Joined: Sep 19, 2006
Posts: 5
|
|
Store it in an array like this
<input type="checkbox" name="option[0]" value="Milk"> Cricket
<input type="checkbox" name="option[1]" value="Butter" > FootBall
<input type="checkbox" name="option[2]" value="Cheese"> BaseBall
and retrieve this array from the request in your Servlet and store it in the db.
|
Best Regards,
Krishnan Iyer
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.
For more information, please read this.
This post has been moved to a more appropriate forum.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ravi Kiran Va
Ranch Hand
Joined: Apr 18, 2009
Posts: 2234
|
|
and retrieve this array from the request in your Servlet and store it in the db
can you completed the above till entering this values in PreparedStatement.
AS you said , i will retrieve this using request.getParameterValues("something") returns an array of values then ??
|
 |
Krishnan Iyer
Greenhorn
Joined: Sep 19, 2006
Posts: 5
|
|
That depends on how you want to store it in the database. You can store it as a comma separated value (Baseball, Cricket, Hockey) etc. or the primary keys of these interests (100, 101, 102) etc. Can you shed some light on how are you planning to store it in the back end.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Krishnan Iyer wrote:That depends on how you want to store it in the database. You can store it as a comma separated value (Baseball, Cricket, Hockey) etc. or the primary keys of these interests (100, 101, 102) etc. Can you shed some light on how are you planning to store it in the back end.
CSV would typically be considered bad design, since you would usually normalize your data model to use atomic values in fields. You would do this because this way you can: i) use the correct data type, ii) apply constraints to the data, iii) easily search the data and iv) you do not have to rely on client applications to maintain your data integrity.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
 |
|
|
subject: storing checkbox data inside database
|
|
|