提示用户输入注册号。更新。 这是我的代码:
System.out.println("Enter Reg no to update: ");
int Uregno = in.nextInt();
String sqlUpdate = "UPDATE vehicle" + "SET name=?" + "ic=?" + "plate=?" + "color=?" + "year=?" + "make=?" + "model=?" + "capacity=?" + "type=?" + "maxload=?"+ "WHERE regno=?"+Uregno;
我不断收到此错误
“您的SQL语法有误;请查看 对应于您的MariaDB服务器版本。.“ ...”
SQL查询在myphpadmin中如下所示:
更新vehicle
设置regno
= [value-1],name
= [value-2],ic
= [value-3],plate
= [值4],color
= [值5],year
= [值6],make
= [值7],model
= [值- 8],capacity
= [值9],type
= [值10],maxload
= [值11]哪里1
我已将regno设置为自动增量键,可以在查询中排除它吗?
答案 0 :(得分:0)
确保您的查询正确无误:
String sqlUpdate = "UPDATE vehicle " + "SET name=?, " + "ic=?, " + "plate=?, " + "color=?, " + "year=?, " + "make=?, " + "model=?, " + "capacity=?, " + "type=?, " + "maxload=? "+ "WHERE regno=?"+Uregno;
并确保您传递正确的参数。
答案 1 :(得分:0)
如果不连接语句的每个部分,则很容易发现错误:
String sqlUpdate =
"UPDATE vehicle SET name=?, ic=?, plate=?, color=?, year=?, make=?, model=?, capacity=?, type=?, maxload=? WHERE regno=?"
还有最后的连接:
+Uregno
将给出语法错误。
如果Uregno
是您要传递给WHERE
参数的值,则应像使用?
占位符(带有PreparedStatement
)的所有其他参数一样传递它。
或删除最后的?
并像这样传递它:
String sqlUpdate =
"UPDATE vehicle SET name=?, ic=?, plate=?, color=?, year=?, make=?, model=?, capacity=?, type=?, maxload=? WHERE regno=" + Uregno;