gpt4 book ai didi

java 从数组中插入/更新表中的单个列

转载 作者:行者123 更新时间:2023-11-29 18:14:25 25 4
gpt4 key购买 nike

如何在表中插入/更新单个列。我想从数组值填充该列。 enter image description here

我只想插入/更新inGram表。

我已经尝试过这个但没有成功:

String sql="INSERT INTO total_ingredient (inGram) VALUES('"+subtractIngredent[0]+"',"
+ " '"+subtractIngredent[1]+"','"+subtractIngredent[2]+"',"
+ "'"+subtractIngredent[3]+"','"+subtractIngredent[4]+"',"
+ "'"+subtractIngredent[5]+"','"+subtractIngredent[6]+"', )";

谢谢。

最佳答案

这应该写成:

String sql="INSERT INTO total_ingredient (inGram) VALUES('"+subtractIngredent[0]+"'),"
+ "('"+subtractIngredent[1]+"'),('"+subtractIngredent[2]+"'),"
+ "('"+subtractIngredent[3]+"'),('"+subtractIngredent[4]+"'),"
+ "('"+subtractIngredent[5]+"'),('"+subtractIngredent[6]+"')";

要使您的代码处理任意大小的数组,您应该考虑使用循环。正如 JB Nizer 提到的,考虑使用准备好的语句而不是自己生成查询。

关于java 从数组中插入/更新表中的单个列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47145583/

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