MultiSelect Array (Javascript to MySql)

MultiSelect Array (Javascript to MySql)

本文关键字:MySql to Javascript Array MultiSelect      更新时间:2023-09-26

我已经做了一个多重选择:客户端

<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>

这是服务器

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 + "')");

但是在数据库中,它返回的不是United States, United Kingdom,而是[Ljava.lang.String;@7780d0fe

显然,如果我写String totcountry = request.getParameterValues("country")[0]+","+request.getParameterValues("country")[1];,它可以工作,但你必须选择两个国家…我哪里错了?谢谢! !

在查询中使用String.join(",", totcountry)。tocountry是一个数组,因此将其转换为String将产生一个引用id,如您所得到的。