File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes storing checkbox data inside database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "storing checkbox data inside database" Watch "storing checkbox data inside database" New topic
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: 61769
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing checkbox data inside database