aspose file tools*
The moose likes JDBC and the fly likes How to insert multiple selection from JSP to MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to insert multiple selection from JSP to MySQL" Watch "How to insert multiple selection from JSP to MySQL" New topic
Author

How to insert multiple selection from JSP to MySQL

Rebecca Green
Greenhorn

Joined: Dec 25, 2009
Posts: 16
Hi,

I want to know whether there is any mysql query to insert mulitple values taken from a jsp page... (Languages known : English, Spanish) into a single column. I mean, how do i insert both these values into the Language column in the database ?

Can anyone tell me the answer?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

The answer depends on your scenario. You can save it as a comma separated String. Not necessarily a JSP related question


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Rebecca Green
Greenhorn

Joined: Dec 25, 2009
Posts: 16
Can you give the exact query ?
I am using it in a JSP page... so thought I might tel it here...
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Best not write SQL statements in a JSP. A JSP is a view, nothing more.

Can you give the exact query ?


How can I give you one when I know nothing of the table details. It should be a trivial insert / update. I am sure you can figure it out
Costi Ciudatu
Ranch Hand

Joined: Oct 24, 2006
Posts: 74
Rebecca Green wrote:...how do i insert both these values into the Language column in the database ?

You do not insert two values in a single column. You need to end up with only one value that contains all those languages: for instance, the string "English, Spanish". Or you could try to see if normalization would help you here (keep the languages in a different table that has a many-to-many relationship with the other table).
Rebecca Green
Greenhorn

Joined: Dec 25, 2009
Posts: 16
I found the solution... rather simple one ;)
I just retrieved the multiple select values into a string array using getParameterValues and used another string array to store all these values (comma seperated). I then inserted this string into the database.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to insert multiple selection from JSP to MySQL