public void Update(String name, String mobile, String email, String car, String model, String year, String color, String plate_no, String plateletters,String gear, String km, String date,String licesnse,String status, String notes){ Connection conn = null; try{ conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD); System.out.println("connected"); Statement stmt = (Statement) conn.createStatement(); String ins = "update car" + "set Name = '"+name+"' , " + "Email = '"+email+"' , " + "Car = '"+car+"' , " + "Model = '"+model+"' , " + "Year = '"+year+"' , " + "Color = '"+color+"' , " + "Plateno = '"+plate_no+"' , " + "Plateletters = '"+plateletters+"' , " + "Gearbox = '"+gear+"' , " + "Km = '"+km+"' , " + "Date = '"+date+"' , " + "License = '"+licesnse+"' , " + "Status = '"+status+"' , " + "Notes = '"+notes+"' " + "where Mobile = '"+mobile+"' "; stmt.execute(ins); }catch(SQLException e){ JOptionPane.showMessageDialog(null, e.getMessage()); System.err.println(e); return; }}**我试过准备好的声明,stmt.executeUpdate(ins);但没有任何效果!!请帮忙!**错误 :java.sql.SQLSyntaxErrorException: 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行附近使用正确的语法 '='ahmed' , Email = 'ahmed@hotmail.com' , Car = 'honda' , Model = 'hondaz' , Yea'
2 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
您需要确保在 SQL 查询中的元素之间添加适当的空间:
String ins = "update car"
应该
String ins = "update car "
这样做的一个好方法是在您的数据库查询工具(SQL 开发人员、phpMyAdmin 等)中编写和执行您的 SQL,并在尝试用 Java 重写之前确保您的语法正确。
添加回答
举报
0/150
提交
取消