如何在表中插入/更新单个列。我想从数组值填充该列。 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/