如下是sql的update语句语法报错,请问该怎么解决?

String sql = "UPDATE `menu`.`chifood` SET " +
"id = '" + menu.getName() + "'," +
"price = " + menu.getPrice() + "'," +
"amount = '" + menu.getAmount() + "'," +
"WHERE id = '" + menu.getId().trim() +"'";
(ps:menu是数据库名,chifood是表名)

沧海一幻觉
浏览 258回答 3
3回答

动漫人物

price 应该是数值,不需要加‘号,price = " + menu.getPrice() + "'," (多了一个单引号)amount = '" + menu.getAmount() + "'," + 也多了一个单引号String sql = "UPDATE [menu].[chifood] SET " +"id = '" + menu.getName() + "'," +"price = " + menu.getPrice() + "," +"amount = '" + menu.getAmount() + "'," +"WHERE id = '" + menu.getId().trim() +"'";

牧羊人nacy

我觉得应该是:"UPDATE menu.chifood t SET " +"t.name = '" + menu.getName() + "'," +" t.price = " + menu.getPrice() + "', " +" t.amount = '" + menu.getAmount() + "'," +"WHERE t.id = '" + menu.getId().trim() +"'";你的"id = '" + menu.getName() + "'," 这个东西id你是使用什么规则的?怎么会把get到的name插入到id上去?表名上不需要引起来吧。

繁星coding

改为String sql = "UPDATE menu.chifood SET " +"id = '" + menu.getName() + "'," +"price = "' + menu.getPrice() + "'," +"amount = '" + menu.getAmount() + "' " +"WHERE id = '" + menu.getId().trim() +"'";
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
MySQL