猿问

jdbc 应用程序更新 sql 对我不起作用,任何想法

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'


ABOUTYOU
浏览 186回答 2
2回答

明月笑刀无情

您需要确保在 SQL 查询中的元素之间添加适当的空间: String ins = "update car"应该 String ins = "update car "这样做的一个好方法是在您的数据库查询工具(SQL 开发人员、phpMyAdmin 等)中编写和执行您的 SQL,并在尝试用 Java 重写之前确保您的语法正确。
随时随地看视频慕课网APP

相关分类

Java
我要回答