• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is best way to store names array in database and process it?  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I have a User registration form in front end like this

<tr><td>Enroll Course:</td><td>Android<input type="checkbox" name="userCourses" value="Android"/>
Java<input type="checkbox" name="userCourses" value="Java"/>
Web Design<input type="checkbox" name="userCourses" value="Web Design"/>
</td></tr>


I am getting its value in servlet like this



and then I am using simply a setter to insert value in the database

problem is I am getting value store in database something like this

[Ljava.lang.String;@3a1c4d68


its very difficult to get and process these values I am looking for a simple way like in other lenguage in PHP to save and handle this seneraio

What is best way to handle this seneraio in JSP?

Thanks
 
Vidya V Pillai
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a loop to iterate through the array

String[] userCourses=req.getParameterValues("userCourses");
if (userCourses!= null && userCourses.length != 0) {
for (int i = 0; i < userCourses.length; i++) {
out.println(userCourses[i]);
}
}

Something like this....

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to iterate a name Array I am looking for mechanism to directly store that array in database and get back that array and automatically check that if that array contain some values of a checkbox
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Databases (at least relational databases) don't do arrays. This has nothing to do with Java, or JSP, or servlets, or PHP. It's a database thing,

So you need to decide how to model the data in the database before writing any code to store that model.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!