I have a page that populates an Access 2000 database. It works great but when I try and put in more than one value for the select multiple options it only passes one value to my database. Please advise how I can get this to work where it will pass all option values that are selected?
HTML Form page:
JSP action page:
If for example I selected three states it should populate the database like this:
Arizona, Colorado, Idaho
Please advise because none of my books show how I can do this.
HTML Form page:
Code:
State:
<select name="State" multiple size="4">
<option value="Arizona">Arizona</option>
<option value="Colorado">Colorado</option>
<option value="Idaho">Idaho</option>
<option value="Oregon">Oregon</option>
</select>
<br>
Comments: <input type="text" name="Comments">
JSP action page:
Code:
//Database connection etc here...
String myQuery = "Insert into TableOne (State,Comments) VALUES (?,?)";
statement = connection.prepareStatement(myQuery);
statement.setString(1,request.getParameter("State"));
statement.setString(2,request.getParameter("Comments"));
//I also tried this and it didnt populate the database:
String myState[] = request.getParameterValues("State");
for(int i = 0;i < myState.length;i++)
{
statement.setString(3,request.getParameter(myState[i]));
}
statement.executeUpdate();
If for example I selected three states it should populate the database like this:
Arizona, Colorado, Idaho
Please advise because none of my books show how I can do this.