• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

save checked value in checkbox to database

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have problem in saving checkbox values to the database. I have a JSP form which has some 18 checkboxes in it. The form is like providing permissions to particular usergroup. Some group are allowed to use some permissions but say an administrator has chance to work on all modules. Once the check boxes are checked, value 1 should get saved in database either through JSP code or servlets code. We are actually using servlet for database connectivity like adding new record to databse, saving the record etc. How do i trap whether the check boxes are checked or not ? After trapping, how do pass the value 0 or 1 to database based on whether checked or unchecked.
SO now how i go about it ? i.e., saving the checked check box value in databse.
ANd also, when i select a particular group, i need to display all the checkboxes + checked checkboxes for which that group is given permissions
Here is a sample of code which i have written:

Do help me in this issue as early as possible. Eagerly waiting fr reply
thanks in advance
regards
kavitha
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try out this,
request.getParametervalues("your checkbox name")
this will give you a string array of check box values that are selected. in your case 1,2,3, .... then do the processing based on the selected values.
Pradheep
 
barbie amr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for ur reply,
I need to tell u one more thing, i am new to both JSP and servlets. so i need to know where i should put the code u told i.e., in JSP page or in servlet or in script. I tried the same code in JSP with <% tags but it didnt work. So do tell me as to where i should put the code
thanks
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in UserGrpCreationServlet.java
you can get all checkboxs' value as a array like this:
String[] checkbox = request.getParametervalues("list");
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Kavi" -

Welcome to the JavaRanch! We don't have many rules around the 'Ranch, but we do require your display name to follow the JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
barbie amr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Welsh,
I am able to trap the checked items in the servlet. Thanks a lot. Now how do i save these into the database. As i have already said i have 5 rows and each row has 3 columns with 1 check box in each column. Suppose the user clicks 1st row 2nd col, 2nd row 3rd adn 4th column, 5th row 1st, 2nd & 3rd columns. In the database also the rows stands for rows and 3 columns stands fr columns (fields). Can anyone advice me as to how to achieve at this. I want to store in the database as 1 fr check boxes clicked and in all other cases as 0.
In the database i want a format like this
------------------------------------------------
GrpName Moduleid aR eR dR
------------------------------------------------
S1 M1 1 0 0
S1 M2 0 1 1
S1 M3 1 1 1
S2 M1 0 0 1
S2 M2 1 0 1
S2 M3 1 0 1
..............
wherein ar, er, dr stands for colums as check boxes. When it is checked, 1 is stored otherwise 0. How od i write insert query fr that?
sorry
 
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic