gpt4 book ai didi

javascript - 多选数组(Javascript 到 MySql)

转载 作者:行者123 更新时间:2023-11-29 22:04:50 24 4
gpt4 key购买 nike

我做了多项选择:这是客户端

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

但在数据库中,而不是美国、英国,它返回类似 [Ljava.lang.String;@7780d0fe

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

最佳答案

在查询中使用String.join(",", totcountry)。 totcountry 是一个数组,因此将其转换为字符串会产生像您得到的这样的引用 id。

关于javascript - 多选数组(Javascript 到 MySql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32255647/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com