I recently implemented a multiselect feature on the client side:
<select name="country" data-placeholder="Choose a Country..." tabindex="2">
<option name="country" value="United States">United States</option>
<option name="country" value="United Kingdom">United Kingdom</option>
</select>
Here's the server-side code involved:
String[] totcountry = request.getParameterValues("country");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db",
"root", "admin");
Statement st = con.createStatement();
int var = st.executeUpdate("insert into table(totcountry) values ('" + totcountry + "')");
However, when checking the Database, I noticed that instead of storing 'United States' and 'United Kingdom', it's returning something like [Ljava.lang.String;@7780d0fe
I tried using
String totcountry = request.getParameterValues("country")[0]+","+request.getParameterValues("country")[1];
, which does work but requires selecting both countries. Where could my mistake be?
Thanks!!