Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

storing checkbox data inside database

 
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??
 
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.
 
Sheriff
Posts: 67399
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.



 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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.
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic