File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes checkboxes from a query , How to ????? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "checkboxes from a query , How to ?????" Watch "checkboxes from a query , How to ?????" New topic
Author

checkboxes from a query , How to ?????

majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
I am trying to do this :
when a user login he will be presented with a form that has his skills (he already submited in this form), now he can change his skilles by checking or unchecking the checkboxes and when submit all are saved in a table in a database.

table : user_table (userID, username).
table : const_skills (skilID , value).
table : lookup_skills (lkupID, userID, skilID).

My problem here is how to populate checked and unchecked checkboxes from database.

Problem 1 ::
Let say a user login for the first time (now we have his userID in a session), then he has a form that lists :

Please check your skills :
checkbox1 JSP
checkbox2 JAVA
checkbox3 HTML

the when he submit the form, only the skills with checkboxes he checked are inserted in the lookup_skills table.
My question here is how to construct the checkboxes in the form using the query : select * from const_skills ? in an other word :
<input type="checkbox" value= the first skilID from the query,
how to test the checked if it's false or true, />
<input type="checkbox" value= the 2nd skilID from the query,
how to test the checked if it's false or true, />
....



Problem 2 ::
Next time the user will login he will see in the form all the skills and his skills are checkec.

Please help me.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410


[ September 22, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Hi Ben, thank you,
Could you please show me how to do it from ResultSet that we get from the join query until the construction of the checkboxex.
thank you, your help is appreciated.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I wouldn't put database code directly into a servlet.
I would perform the DB operation in a plain old Java object (POJO) and return the data to the servlet as a list of beans or a 2D array.

I also wouldn't build HTML strings directly in a servlet. I would do that from a JSP.

That being said:
Assign the value to a boolean variable by testing the data returned in your result set.

majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Please take a look to the tables, I don't have a column has_java .
thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you looking for help with checkboxes or do you not know how to query a database to get the needed values?
majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Hi,
I know how to query the database, to get the result I have only to join this two tables :
table : const_skills (skilID , value).
table : lookup_skills (lkupID, userID, skilID).

using userID = userid from the session after login, so what to do after getting all the pairs (skillID, value) from the resultSet to show all the element in the table const_skills and all matching values are checkec.
thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you know how to query the database to the the table of data,
and you know how to build the checkbox by comparing the skill.value from each row, what are you stuck on.

I assume the skill.id is a texual description of the skill since there are only two columns.



If that's not what you mean, you'll need to describe what is that you're stuck on in a little more detail.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: checkboxes from a query , How to ?????