• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing checkbox data inside database

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Krishnan Iyer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic